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
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 <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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.