we are developing subdomains and we want to redirect following dynamic url to static: Let' say main domain name is http://example.com and sub domain name is sub1.example.com. The URLs which are being getting created are in the format sub1.example.com?index12.php?id=1. Now how should we redirect sub1.example.com?index12.php?id=1 to sub1.example.com/abc-def-ghi permanently(301) for any individual page where "ABC DEF GHI" is a name (title) given to an individual page. Please post an exact redirect rule needed for this permanent redirection
Don't use redirect but rewrite rule. Depending on what you need the following can be used. But for you to better understand or research what you want just google htaccess rewrite query string Options+FollowSymlinksRewriteEngineOn# specific ruleRewriteCond%{QUERY_STRING}^([^=]+)=([^&]+)RewriteRule^(constant)$ /index.php?url=$1&type=%1&task=%2[L]# general catch-allRewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule^(.*)$ index.php?url=$1 [L] Code (markup): or RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] Code (markup):
I believe WebStumblr's second example is used in Wordpress .htaccess file. It's good if you have many pages - indeed it'd be pain to hard-code all of your hundred pages to .htaccess. Anyway, the above solution reroutes visitors requests to index.php. Thus, if you use the above solution, you should also write a URL handler to index.php that captures the URL client requested and fetches the correct code from database. It's effective way yet perhaps not the best if you have, say, just 5 pages. In the case of having just a handful of pages, you can hard-code everything to .htaccess. Like this: Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^my_page_name/?$ index.php?id=1 [L,QSA] RewriteRule ^my_other_page_name/?$ index.php?id=2 [L,QSA] RewriteRule ^my_third_page_name/?$ index.php?id=3 [L,QSA] Code (markup): Now, when you go to sub1.example.com/my_page_name/, contents of sub1.example.com/index.php?id=1 are actually shown while sub1.example.com/my_page_name/ is the URL shown in the address bar. Hope this helps.