i am trying to use .htaccess 301 redirect but its not working
i am using following syntax in my .htaccess file
RewriteRule ^our_services.html http://localhost/site/our-services [R=301,L]
but when i open the page page redirect to
http://localhost/Applications/XAMPP/xamppfiles/htdocs/site/our-services
how to write correct one ?
i want to redirect
our_services.html to our-services
in same domain
Thanks
Can you try relative paths like this:
If in DOCUMENT_ROOT:
RewriteEngine On
RewriteBase /
RewriteRule ^our_services\.html$ /our-services [R=301,L,NC]
If in DOCUMENT_ROOT/site:
RewriteEngine On
RewriteBase /site/
RewriteRule ^our_services\.html$ our-services [R=301,L,NC]
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 have bunch of folders and files in folder "front". I want to remove "front" from url. I write htacess but it gives 404 error.
RewriteEngine On
RewriteBase /
RewriteRule ^front/(.*)$ /test/$1 [L,NC,R]
I want to rewrite url like this :
http://localhost/test/front/abc/abc.php
to
http://localhost/test/abc/abc
You have it back to front
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)$ /test/front/$1 [L,NC,R]
Try adding this to the htaccess file in your document root, preferably above any rules you may already have there:
RewriteEngine On
RewriteRule ^test/(.*)$ /front/$1 [L,R=301]
I want to rewrite my URL:
http://jainpopulationregister.com/page.php?action=about
to:
http://jainpopulationregister.com/page/action/about/
with URL rewriting
My current URL rewrite code is as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteRule page/action/(.*)/ page.php?action=$1
RewriteRule page/action/(.*) page.php?action=$1
But when I place this in my root folder, nothing seems to happen. What am I doing wrong?
You want to redirect from
http://jainpopulationregister.com/page.php?action=about
to
http://jainpopulationregister.com/page/action/about/
but your redirect rule does exactly the opposite. Assuming that you really want to redirect from /page.php?action=about to /page/action/about/, use the following configuration in htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^action=(.*)$
RewriteRule ^(.*)$ /page/action/%1/? [R=302,L]
RewriteRule ^page/action/([a-zA-Z0-9]+)/$ pages.php?action=$1 [NC,L]
In "pages.php" file get the action $_GET['action'];
I'm attempting to perform a simple 301 redirect via htaccess, the redirect works but adds "?folder=X" to the URL.
For instance:
Redirect 301 /pets http://www.mydomain.com/discount-pet-products
Returns:
http://www.mydomain.com/discount-pet-products?folder=pets
How do I remove this?
Here is my htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
Redirect 301 /pets http://www.mydomain.com/discount-pet-products
RewriteRule ^([0-9a-zA-Z-]+)$ load.php?folder=$1 [L]
Try this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/pets$ http://www.mydomain.com/discount-pet-products? [R=301,L]
RewriteRule ^([0-9a-zA-Z-]+)$ load.php?folder=$1 [L]
Try this code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^pets/$ /discount-pet-products? [R=301,L]
RewriteRule ^([0-9a-zA-Z-]+)/?$ load.php?folder=$1 [L,QSA]
Make sure to test this in a new browser to avoid browser caching issues.
The answer was placing redirect at top of .htaccess file, before anything
RewriteRule ^pets$ http://www.mydomain.co.uk/discount-pet-products [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
this is on my server (mypage.com) in .htaccess file.
How can i make:
If i open here.mypage.com then this redirect me to mypage.com/here.html
If i open mypage.com/now then this redirect me to mypage.com/now/test.html
My page is in PHP.
1.If i open here.mypage.com then this redirect me to mypage.com/here.html
As long as here.mypage.com is the same document root the htaccess file is in, add:
RewriteCond %{HTTP_HOST} ^here\.mypage\.com$ [NC]
RewriteRule ^$ http://mypage.com/here.html [R=301,L]
2.If i open mypage.com/now then this redirect me to mypage.com/now/test.html
Add:
RewriteCond %{HTTP_HOST} ^mypage\.com$ [NC]
RewriteRule ^now$ /now/test.html [L]
RewriteEngine on
RewriteRule ^now$ now/test.html
That's for the second one. The first one, you'll have to use your website cPanel (or similar) make a new subdomain, and point the subdomain to the main public_html folder, but we'll likely need more information about your server to give exact help.
EDIT:
RewriteCond %{HTTP_HOST} ^here.mypage.com [NC]
RewriteRule ^/here.html [L]
That should do the subdomain.
to redirect here.mypage.com to mypage.com/here.html, this will require more than to add a rule to the .htaccess (see => Setting a subdomain).
For the other one you can add :
RewriteRule ^now$ now/test.html
Give this a try:
Redirect 301 here.mypage.com mypage.com/here.html
Redirect 301 mypage.com/now mypage.com/now/test.html