0

I have a project set up on server which use apache web server with PHP as scripting language. On my local machine (using XAMPP) .htaccess is working. I tested it with below script and it gets redirect to Google. Below script is very first line of the file.

RewriteEngine On
Options +FollowSymLinks
RewriteRule ^test\.php http://www.google.com/? [R=301,L]

But the same config on server is not working. I confirm mod_rewrite is enabled. I do not have access to server configuration and I can see and confirm only through phpinfo().

Symfony 2.6 + apache 2.2 + php 5.5.23 is the configuration.

Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
Manojkumar
  • 1,351
  • 5
  • 35
  • 63
  • what happen when you access your url?? – Mudassar Saiyed Feb 24 '17 at 06:22
  • I tested it with test.php file inside root directory. It dosen't redirect to Google. Instead it loads test.php page contents. – Manojkumar Feb 24 '17 at 06:28
  • Do you have `AllowOverride All` ? – Gogol Feb 24 '17 at 06:29
  • @Gogol AllowOverride All is a option in apache config for which I do not have access to. – Manojkumar Feb 24 '17 at 06:31
  • try placing that in your htaccess – Gogol Feb 24 '17 at 06:31
  • I tried with this below code. I think .htacess is not getting read by the server. ` Options FollowSymLinks AllowOverride All Order allow,deny Allow from all ` – Manojkumar Feb 24 '17 at 06:51
  • .htaccess is a means to let non-admins modify directory configurations for Apache, it has nothing to do with mod_rewrite. Inside .htaccess you can define other things rather than just rewrite directives. – Daniel Ferradal Feb 24 '17 at 09:18
  • @ezra-s I agree. But I am failing to know if htaccess is getting read by server or not. I placed some random script and thought it would give error. server is not responding with .htaccess file. – Manojkumar Feb 24 '17 at 09:57

1 Answers1

0

It looks like mod-rewrite isnt enabled on your server. You can use the following mod-alias based redirect in htaccess :

Redirect /test.php http://google.com/
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • I added this - `Redirect /test.php http://google.com/` as very first line of .htaccess but it did not redirect. Here I think my web server is not reading .htacess at all.Any clues on how to confirm?. Below is the code I have on .htacess `Redirect /test.php http://google.com/ Options FollowSymLinks AllowOverride All Order allow,deny Allow from all ` – Manojkumar Feb 24 '17 at 06:50
  • directive isnt supported on htaccess context, Yes your server isnt reading the .htaccess otherwise you would get 500 server error for the unsupported directive. – Amit Verma Feb 24 '17 at 06:54
  • Redirect appends anything the client requests and appends it to the destination, OP original rewrite seems not to do that, just rewrite test.php to google, without appending anything, so correct thing would be to just RedirectMatch – Daniel Ferradal Feb 24 '17 at 09:25
  • @ezra-s I know that. But We are redirecting a file not directory. And there is nothing except path_info that will be appended. – Amit Verma Feb 24 '17 at 09:29
  • @starkeen understood but with Redirect if someone requests `http://whatever/test.phpwhateverldsfkflñdksflñksñlfkdsfñldkd` it will redirect to `https://www.google.com/whateverldsfkflñdksflñksñlfkdsfñldkd`. So, basically if you want to redirect a file to something without appending stuff, use RedirectMatch. – Daniel Ferradal Feb 24 '17 at 09:46