I have these pages www. domain .com/index.php?page=Folder-Number-One www. domain .com/index.php?page=Key-Phrase-One I want to create a sub-folder for other files to be under with Folder-Number-One.php file becoming the index file I want to create www. domain .com/Folder-Number-One www. domain .com/Folder-Number-One/Key-Phrase-One.html I have this: RewriteRule ^Folder-Number-One\/(.*)$ index.php?page=Folder-Number-One RewriteRule ^Folder-Number-One/Key-Phrase-One/(.*)$ index.php?page=Key-Phrase-One first rewrite ends up creating domain .com/Folder-Number-One.html but i would rather it be a folder not a file. 2nd rewrite is not working at all. What am i missing? Are my dashed file names causing troublems, or is my rewrite simply wrong? I already have a rewrite rule in there that converts files to .html extension. EDIT I figured out the folder part by removing the (.*)$ (also works with the $ still in it) this now works www. domain .com/Folder-Number-One/ But i still cant get www. domain .com/Folder-Number-One/Key-Phrase-One.html
RewriteRule ^Folder-Number-One/(.*)/$ index.php?page=$1 RewriteRule ^(.*)/$ index.php?page=$1 If Folder-Number-One changes.... RewriteRule ^(.*)/(.*)/$ index.php?page=$2 RewriteRule ^(.*)/$ index.php?page=$1 with $2 being Key-Phrase-One. With index.php?page=Folder-Number-One and index.php?page=Key-Phrase-One both are exactly the same thing so why not just have RewriteRule ^(.*)/$ index.php?page=$1
I think I have to abandon my attempt at making the other files go into the folder. I just cant get it to work. I'll just have to use this RewriteRule ^(.*)/$ index.php?page=$1 and have them all as files off the root, i guess.
I can't get mod_rewrite to work on this site and it's frustrating the @#$3 out of me ... What am I doing wrong??? Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^(.*)\.html$ /pages.php?idpages=$1 [L] RewriteRule ^(.*)\.html$ /description.php?iddesc=$1 [L] RewriteRule ^(.*)/(.*)/(.*)\.html$ /products.php?id=$1&lev1=$2&lev2=$3 [L] RewriteRule ^(.*)/(.*)\.html$ /products.php?id=$1&lev1=$2 [L] RewriteRule ^(.*)\.html$ /products.php?id=$1 [L] Site is cellmansion dot com
Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^([^.]+)/([^.]+)/([^.]+)\.html$ products.php?id=$1&lev1=$2&lev2=$3 [L] RewriteRule ^([^.]+)/([^.]+)\.html$ products.php?id=$1&lev1=$2 [L] RewriteRule ^products/([^.]+)\.html$ products.php?id=$1 [L] RewriteRule ^pages/([^.]+)\.html$ pages.php?idpages=$1 [L] RewriteRule ^description/([^.]+)\.html$ description.php?iddesc=$1 [L]
Hello, I have a very simple question: I have to redirect www.domain.com to www.domain.com/mycmsdirectory because I installed my CMS inside the /mycmsdirectory to keep clean the root I'm using this now Redirect 301 /index.html http://www.site.com/directory/index.php It's works but I think it's not correct (SEO Point of view) and I can do better. Nintendo can you please help me?
Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^index\.html$ directory/index.php [L] or RewriteRule ^index\.html$ http://www.domain.com/directory/index.php [R=301,L] for mod_rewrite. Get rid of index\.html for domain.com
hello again I set up a test website based on Wordpress at www.domain.tld/dir I used this code on /.htaccess to redirect all domain.tld requests to www.domain.tld: Options +FollowSymlinks RewriteEngine on RewriteCond %{http_host} ^domain.tld [nc] RewriteRule (.*)$ http://www.domain.tld/$1 [r=301,nc] and all went ok. Problems started when I started to use permalinks under wordpress which create another .htaccess under /dir directory with this options: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /dir/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /dir/index.php [L] </IfModule> # END WordPress This override my general htaccess so I tried to insert inside the previous code and i get: # BEGIN WordPress Options +FollowSymlinks RewriteEngine on RewriteCond %{http_host} ^domain.tld [nc] RewriteRule (.*)$ http://www.domain.tld/$1 [r=301,nc] <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /dir/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /dir/index.php [L] </IfModule> # END WordPress But the fix don't work In particular when I try to access this url: http://domain.tld/dir I get: Moved Permanently The document has moved here (http://domain.tld/dir). Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. Servage.net Cluster (Enhanced Apache) Server at domain.tld Port 80 This is a loop I have a share account and the general config of the webserver redirect requests to domain.tld if you not use the trailing slash. For example: http:www.domain.tld/dir point to domain.tld/dir/ I don't know how to resolve the problem so I'm asking again for help Super Nintendo P.S. I used also other htaccess code like: RewriteEngine on RewriteCond %{HTTP_HOST} !^www.domain.com RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L] RewriteEngine on Options +FollowSymLinks RewriteCond %{HTTP_HOST} ^mydomain\.com RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=permanent,L] but the problems remains
RewriteRule . /dir/index.php [L] doesn't look correct at all. Not even sure if... RewriteRule ^.$ dir/index.php [L] would fix it. For adding / to the URLs, right before the first $ on the RewriteRule lines, add a / I got wordpress and the .htaccess file code it gave out is 49 lines. You might want to make a post over on their message board.
thank you for your fast reply! I'm using Wordpress 2.0.4 I tried to reinstall it and change themes but the code it give me is always that My permalinks structure is: /%year%/%monthnum%/%day%/%category%/%postname%/
I found something interesting here: http://wordpress.org/support/topic/71959?replies=3 I will do some tests and I will report my finding
The code works: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.domain\.tld$ RewriteRule ^(.*) http://www.domain.tld/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^dir/ /dir/index.php [L] </IfModule> # END WordPress The only problem is this: If you call domain.tld/dir it redirects to: www.domain.tld/dir and it redirects to: http://domain.tld/dir/ then to: http://www.domain.tld/dir/ and it finally reach the website So it works but is there a cleaner solution?
Redirect 301 /index.html http://www.domain.tld/dir/ # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.domain\.tld$ RewriteRule ^(.*) http://www.domain.tld/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^dir/ /dir/index.php [L] </IfModule> # END WordPress
Changing the order is all I can think of. Redirect 301 /index.html http://www.domain.tld/dir/ # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^dir/ /dir/index.php [L] RewriteCond %{HTTP_HOST} !^www\.domain\.tld$ RewriteRule ^(.*) http://www.domain.tld/$1 [R=301,L] </IfModule> # END WordPress
Perfect FAQ!! It's seems that you are an expert on this,will be asking for help if needed Thanks,Nintendo!
I am currently rewriting urls from http://www.domain.com/index.php?page=page to http://www.domain.com/site/page/ I would like to redirect users who access the page from index.php?page= and redirect them to /site/page. How would I go about doing this without getting in some horrible mod_rewrite infinite loop?
This is just a guess. If it doesn't do it, you're toast. RewriteCond %{QUERY_STRING} ^page=page(&page=[^&]+)?$ RewriteRule ^index\.php?page=([^.]+)$ http://www.domain.com/site/$1 [R=301,L]