I need make redirect from site/article to site/article/
I use this rule in .htaccess
RewriteRule ^/article(.*)$ http://balttranscom.ru/article/$1 [R=301,L]
but it's not work!
Help!
As shown at the bottom of the mod_rewrite documentation page, rules in .htaccess files aren't passed an initial slash.
RewriteRule ^article(.*)$ http://balttranscom.ru/article/$1 [R=301,L]
Do you have the following line?
RewriteEngine On
Related
I have a problem with my .htaccess file.
In my .htaccess rules if I put this:
RewriteRule ^post/([^/]*)$ /the_post.php?id=$1 [L]
I'll be able to navigate url like this:
http://www.example.com/post/12
But if I try:
http://www.example.com/post/12/
or
http://www.example.com/post/12/something-else-here
The page was not founded.
What is the right way to allow any possible combinations of url?
http://www.example.com/post/12
http://www.example.com/post/12/
http://www.example.com/post/12/something-else-here
Thanks for your time!
With your current rule :
RewriteRule ^post/([^/]*)$ /the_post.php?id=$1 [L]
You can't have any / after post/ in your url. [^/]* means any character except /.
You can try this rule :
RewriteRule ^post/([0-9]+) /the_post.php?id=$1 [L,QSA]
You can use this rule to replace your rule:
RewriteRule ^post/([^/]+)(/[^/]*)?/?$ the_post.php?id=$1 [L,NC,QSA]
I want to rewrite:
www.domain.com/entry/1 or www.domain.com/entry/1/title to www.domain.com/entry.php?id=1
www.domain.com/entry/1/title/page/2 to www.domain.com/entry.php?id=1&page=2
www.domain.com/entry/1/title/comment to www.domain.com/entry.php?id=1&a=comment
I have the following in the .htaccess files
RewriteRule ^entry/(([0-9]+))(?:/([^/]*))?/?$ ./entry.php?id=$1
RewriteRule ^entry/([0-9]+)/([^/]+)/page/([0-9]+)$ ./entry.php?id=$1&page=$3
RewriteRule ^entry/([0-9]+)/([^/]+)/([^/]+)$ ./entry.php?id=$1&a=$3
It's working. I also tried reverse the orders to :
RewriteRule ^entry/(([0-9]+))(?:/([^/]*))?/?$ ./entry.php?id=$1
RewriteRule ^entry/([0-9]+)/([^/]+)/([^/]+)$ ./entry.php?id=$1&a=$3
RewriteRule ^entry/([0-9]+)/([^/]+)/page/([0-9]+)$ ./entry.php?id=$1&page=$3
It's also working. How do the lines on the .htaccess file are executed? Which of the versions above is the more correct one? Thanks!
It shouldn't matter. But be sure to put an [L] at the end of each RewriteRule line so that Apache stops after successfully applying a rule and doesn't loop endlessly.
This is also a very useful tool for testing RewriteRules and whether they work correctly.
Is there a way to redirect to a specific page but adding https and keeping the path relative at the same time?
RewriteEngine On
RewriteRule ^user/([^/]+)/settings/?$ https://%{HTTP_HOST}/settings/settings.php?u=$1 [QSA,L]
The above works well but it's somehow absolute as we start with https://%{HTTP_HOST}
And this makes the end URL to show the exact request: https://www.mydomain.com/settings/settings.php?u=John
Can we, instead, redirect to a page, adding https in a relative way? so that the exact path keeps being hidden and we only see a "folder structure": https://www.mydomain.com/user/John/settings
Thanks for your help!
Trick is to do http->https (R=301) rule on pretty URL before rewriting it internally. So something like this would work:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
RewriteRule ^user/([^/]+)/settings/?$ /settings/settings.php?u=$1 [QSA,L,NC]
I want to rewrite the url in my project.
For example:
http://www.example.com/dashboard/test/ to http://dashboard.example.com/index.php
Also I want to do it for:
http://www.example.com/dashboard/test2/ to http://dashboard.example.com/index.php
Can anyone tell me the idea to rewrite the url?
First you create a .htaccess file in your root.
Than, just put the redirect commands in it.
How to compose a .htaccess and how to create rewrite rules is explained here: http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/
You will need something like:
RewriteRule ^(.*)$ http://dashboard.example.com/$1 [L,QSA]
try this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^test.*$ http://dashboard.example.com/index.php [R=301,L]
I have some code which uses Rewrite engine in my .htaccess file and it specifies the directory for my SERPs. However when someone goes onto search/QUERY/ rather than search/QUERY/PAGE/ it displays a 404 error. Same with just search/.
I want it so that if someone just goes to search/QUERY/ that it redirects them to search/QUERY/1/ and for just search/ it redirects them to my homepage /. I have included a copy of my code below.
RewriteEngine on
RewriteRule ^search/([^/]+)/([^/]+)/?$ search.php?q=$1&category=web&d=$2
Can anyone help me with this problem?
Thanks in advance, Callum
Try this code in your htaccess :
RewriteEngine on
RewriteRule ^search/?$ / [R=301,L]
RewriteRule ^search/([^/]+)/?$ /search/$1/1/ [R=301,L]
RewriteRule ^search/([^/]+)/([0-9]+)/?$ search.php?q=$1&category=web&d=$2 [NC,L]
You can create multiple RewriteRule statements to accomplish this. (Make sure to omit the [R] flag on intermediate rules if you use it!)
The rule you posted will only rewrite if it's of the form /search/query/n/, so write a regular expression matching search/query that redirects to /search/query/1. Do the same to redirect home with no query.
Try these additional 2 rules in your .htaccess file:
RewriteRule ^search/([^/]+)/$ /search/$1/1/ [R=301,L]
RewriteRule ^search/?$ / [R=301,L]