Jump to content

Mod Rewrite Only Works Sometimes?


unemployment

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/267990-mod-rewrite-only-works-sometimes/
Share on other sites

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 ?

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.