I'd like to use .htaccess to redirect all requests to the www.
version of the domain, and to the files stored in a "new" subdirectory of the root. However, the "new" subdirectory should be hidden and also any index.php occurance in the URL. Is this possible? Example: http://mydomain.de/?x=100
would direct to http://www.mydomain.de/index.php?x=100
, but only show http://www.mydomain.de?x=100
in the browser.
So far I tried it with
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.de$
RewriteRule ^new/index.php(.*)$ /$1 \
RewriteRule (.*) http://www.mydomain\.de/new [R=301,L]
but that doesn't work.
Edit w/ latest code, I've commented out the lines that led to a server error:
# add www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
# remove /new/ from URL
# RewriteCond %{THE_REQUEST} /new/(\S*)\s [NC]
# RewriteRule ^ /%1 [L,R=302]
# remove /index.php from URL
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC]
# redirect everything to /new/
RewriteCond %{HTTP_HOST} !^/?$
RewriteRule ^((?!new).*)$ http://www.xn--krisen-lsen-yfb.at/new/$1 [L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule !^new/ new%{REQUEST_URI} [L,NC]
With the above htaccess code, "/new" and "index.php" still remain in the URL. Also, redirect to "www." doesn't work if the URL contains parameters, like in " http://krisen-lösen.at/new/index.php/das-team ".
Have it like this in your site root .htaccess:
RewriteEngine on
# add www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
# remove /new/ from URL
RewriteCond %{THE_REQUEST} /new/(\S*)\s [NC]
RewriteRule ^ /%1 [L,R=302]
# remove /index.php from URL
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC]
# route everything to /new/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^new/ new%{REQUEST_URI} [L,NC]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.