Jump to content

Impossible: redirect any url to https://www.domain.com/ AND rewrite to index.php


Recommended Posts

This rewrites to index.php:

 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,NS]

 

...and I just can't get it to also redirect (301) to https://www.domain.com/page/var/ etc (with trailing slashed and https).

Can you post your code.

 

PS Apache has a special directive for your rewrite to index.php FallbackResource

 

From Apache Docs:

It is frequently desirable to have a single file or resource handle all requests to a particular directory, except those requests that correspond to an existing file or script. This is often referred to as a 'front controller.'

 

In earlier versions of httpd, this effect typically required mod_rewrite, and the use of the -f and -d tests for file and directory existence. This now requires only one line of configuration.

Hi,

 

So far, I have this. It works, but I'm guessing I could improve on it a bit. It does work though as it is. I am using the Rackspace Cloud server, which I believe has the need for some slight adjustments.

 

RewriteEngine On

# required on my server
RewriteBase /

# redirect to full correct url if missing trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ https://www.domain.co.uk/$1/ [R=301,L]

# redirect to full correct url if not complete
rewritecond %{http_host} ^domain.co.uk [nc,OR]
# the next line may be specific to my server
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://www.domain.co.uk/$1 [R=301,L]

# use index.php for all requests
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,NS]

 

Thanks.

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.