unemployment Posted September 4, 2012 Share Posted September 4, 2012 I don't understand why this doesn't work properly. I checked my php_info page and yes, I have mod rewrite enabled. In my htaccess file I have <IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] </IfModule> # Index.php will redirect to the subdomain RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ RewriteRule ^index\.php$ http://jasonbiondo.com/ [R=301,L] # Remove the .php extension RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] The second mod rewrite seems to be the only one that works! Is there any particular reason why that would be the case? The first one should redirect the user from www.mysite.com to mysite.com and the last one should always remove the .php extension but it doesn't work. This is how I have my host file set up. <VirtualHost *:80> DocumentRoot /var/www/jasonbiondo.com/jasonbiondo.com ServerName jasonbiondo.com <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost> Quote Link to comment https://forums.phpfreaks.com/topic/267990-mod-rewrite-only-works-sometimes/ Share on other sites More sharing options...
requinix Posted September 4, 2012 Share Posted September 4, 2012 The third one doesn't actually remove the extension - just allows you to omit it (for .php files). To remove it you'd need RewriteCond %{REQUEST_URI} (.*)\.php$ RewriteRule ^ %1 [R=301,L] As for the first one, what if you take it out of the ? Quote Link to comment https://forums.phpfreaks.com/topic/267990-mod-rewrite-only-works-sometimes/#findComment-1375168 Share on other sites More sharing options...
unemployment Posted September 4, 2012 Author Share Posted September 4, 2012 The third one doesn't actually remove the extension - just allows you to omit it (for .php files). To remove it you'd need RewriteCond %{REQUEST_URI} (.*)\.php$ RewriteRule ^ %1 [R=301,L] As for the first one, what if you take it out of the <IfModule>? Removing the IF didn't do anything. And adding in your rewrite makes me return a redirect loop error. Any thoughts? RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] # Index.php will redirect to the subdomain RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ RewriteRule ^index\.php$ http://jasonbiondo.com/ [R=301,L] RewriteCond %{REQUEST_URI} (.*)\.php$ RewriteRule ^ %1 [R=301,L] # Remove the .php extension RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/267990-mod-rewrite-only-works-sometimes/#findComment-1375174 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.