I would like to rename, not redirect a number of URL's I have on my website using the .htaccess file:
from http://siteaddress.com/?chapter=1 to http://siteaddress.com/about.
As I'm quite new to dabbling with the .htaccess file and I can't afford to brake anything, how would I be able to achieve this in a safe and simple manor?
Thank you.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?chapter=1\s [NC]
RewriteRule ^ /about? [R=302,L]
RewriteRule ^about/?$ /?chapter=1 [L,NC,QSA]
With above in place now when you try to visit http://site.com/about it will internally forward your request to: http://site.com/?chapter=1 while not changing the URL in the browser (no redirect). When you visit http://site.com/?chapter=1 it will be externally redirected to http://site.com/about .
Related
am working on making my site urls search engine friendly and for which am rewriting urls with GET parameters and so i have done rewriting but now htaccess is not pointing that url to php file which is suppose to handle the url
my old url
www.domain.com/foo/myfile.php?nid=554
new rewritten url with php
www.domain.com/foo/554-demo-page-title
my current htaccess rules which work for old urls but not for new
Options +FollowSymLinks
RewriteEngine On
#RewriteCond %{SCRIPT_FILENAME} !-d
#RewriteCond %{SCRIPT_FILENAME} !-f
RewriteBase /
RewriteRule ^([0-9]+)-(.*) ./foo/myfile.php?nid=$1 [NC]
so i want to that both old and new urls land on /foo/myfile.php becuase myfile.php can handle both urls incase of old url it rewrite and redirect as new url , i played for few hours with htaccess rules but no success
You can use this rule in site root .htaccess (assuming there is .htaccess inside foo/ directory):
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^foo/(\d+)-.*$ foo/myfile.php [L,QSA,NC]
If you already have /foo/.htaccess then use this rule inside that file:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /foo/
RewriteRule ^(\d+)-.*$ myfile.php [L,QSA]
I didn' try anything.
But i want to clear one question.
I have a link www.abc.com/meeting/
Is it possible to rewrite abc to my own words
eg: www.myown.com/meeting/
Is it possible with URL rewriting
This is the dynamic version which will redirect all the url to specified domain. So www.abc.com/* will be redirected to www.myown.com/*
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.abc.com/.$ [NC]
RewriteRule ^(.*)$ http://www.myown.com/$1 [R=301,L]
Make sure your Apache have enabled option Rewrite mode
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^abc.com/meeting/.*$ http://www.myown.com/meeting/ [R=301,L]
Use this code in filename as .htaccess save this file in your root folder
allow .htaccess file in your server. In xampp it bydefault activated
I need to make redirections from a sub-directory to the parent directory.
In other words I have to redirect anything matching
http://exemple.com/portfolio/product1
to :
http://exemple.com/product1
Is there any way to do that with URL REWRITE ?
Thanks
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^portfolio/(.*)$ /$1 [L,R=301,NC]
You want to put this into .htaccess inside the directory that you want to be redirrected
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/parent
RewriteRule ^(.*)?$ http://%{HTTP_HOST}/parent
I have a problem i.e suppose the url is www.example.com/view.php?id=1 but I want the url is like that www.example.com/view/id/1 , seperately I get htaccess for hide extension or replace '?' by slash but both are not working please anybody help me .I want .htaccess working for both(extension hide and replace slash) and please make it general that is htaccess working for any page not any particular page.thanks in advance
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# external redirect from /view.php?id=1 to /view/id/1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+([^.]+)\.php\?([^=]+)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [L,R=301]
# internal forward from /view/id/1 to /view.php?id=1
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?$2=$3 [L,QSA]
I need to redirect a page like this:
http://example.com/clients/themes?domain=localhost.com
this link should be redirected to skin.php which is in the same directory.
Can any one help me? Thanks.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^domain=localhost\.com$ [NC]
RewriteRule ^clients/themes/?$ clients/skin.php? [L,NC]
This will internally forward your request to /clients/skin.php stripping out query string. If you want query string as well then remove ? after skin.php.