I'm trying to rewrite all urls of the following pattern:
http://example.com/csfdg/anything
into http://example.com/csfdg/index.html
my .htaccess file at the root level contains this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule \/csfdg\/.* /csfdg/index.html [L]
The checker at http://htaccess.madewithlove.be/ tells me that it would rewrite my URLs the way I want, but when I go to http://example.com/csfdg/anything I just get a 404. It's very hard to tell what's going on, but I know that the RewriteEngine is working because if I mess with it enough I can get 500 errors to happen :)
Any thoughts? Thanks
You can use this :
RewriteEngine on
RewriteCond %{REQUEST_URI} !index\.html$
RewriteRule ^([^/]+)/.+$ /$1/index.html [L]
RewriteConditon is important here to avoid rewriting /foo/index.html to itself.
Related
I have looked through the other posted questions and I cant seem to find an answer that pertains to my specific situation. I have already established dynamic urls (rr.php?rrid=5) and I am switching over to seo friendly urls (rr/5/name/) I have that part working
RewriteRule ^rr/([0-9]+)/([a-z\+\-]+)/?$ /rr.php?rrid=$1 [L]
The problem I am having is implementing a 301 redirect to tell the search engines that the urls have changed without causing a redirect loop. Also, I have hundreds of rrid=# and I would like a way to do the 301 similar to the above rule where the /name/ portion is different depending on the rrid=#
I know there is a way to add &rewrite to the above rule but I cant figure out how to write the 301 redirect without having to go through and do each one individually.
You need to have an additional rule for 301 handling. Place this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+rr\.php\?rrrid=([0-9]+) [NC]
RewriteRule ^ /rr/%1? [R=302,L]
RewriteRule ^rr/([0-9]+)/?$ /rr.php?rrid=$1 [L,QSA]
RewriteRule ^rr/([0-9]+)/([a-z+-]+)/?$ /rr.php?rrid=$1 [L,QSA]
Currently my URLS are horrible.
They are like:
http://www.racebooking.net/single_news.php?id=211
And i want them to look better and to be more SEO Friendly, like
http://www.racebooking.net/news/video-122.html
I am going to do it through Apache .htaccess. Surfing the web i found many different opinions about SEO. Some people say it's not good to use RewriteRule because it creates duplicated content and kills pagerank, but you have to send a 301 message.
Here comes the question: it's better to use
RewriteRule Pattern Substitution
or
RewriteRule Pattern Substitution [R=301,L]
to make my URLS look better without worsening my SEO?
Place this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+single_news\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /news/%1.html? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^news/([^/.]+)/?$ /single_news.php?id=$1 [L,QSA,NC]
I read some tutorials about getting clean urls. I tried some of the codes they gave in the tutorials but I can't get a simple example to run...
I would like to change: http://domain.com/brigandze/mannen/index.php?p=0
To: http://domain.com/brigandze/mannen/0/
I used this code and put it in the directory domain.com/brigandze/mannen/
I have this code in my htaccesfile:
RewriteEngine on
RewriteRule ^([0-9]+)/?$ index.php?p=$1 [NC,L]
You need to either set your RewriteBase correctly or use the full path in your RewriteRule (see here for RewriteBase documentation).
RewriteBase /brigandze/mannen/
RewriteEngine on
RewriteRule ^([0-9]+)/?$ index.php?p=$1 [NC,L]
or
RewriteEngine on
RewriteRule ^brigandze/mannen/([0-9]+)/?$ brigandze/mannen/index.php?p=$1 [NC,L]
The problem is that the web server looks at URLs starting from the DocumentRoot unless you tell it otherwise. In your case, that means that your rule is trying to rewrite
http://domain.com/0/
By adding the RewriteBase, it will look at the correct place.
This is the initial url:
http://example.net/any/number/folders/param1/param2/value2/value1
and this is the url we need to be mapped to:
http://example.com/any/number/folders/param1.php?param1=value1¶m2=value2
The script param1.php is under directory param1 and both exist.
I have these rules but don't work. Usually get a 404 error.
RewriteEngine On
RewriteBase /param1
RewriteCond %{REQUEST_URI} /param1
RewriteRule ^(.*)(param1)/(.*)/(.*)/(.*)$ http://example.com/$1/$2.php?$2=$5&$2=$3 [L,R=301,QSA]
I have been trying to make it work for hours and also searched for something similar. At this point I am not even sure if it is possible.
Any suggestion or solution will be really appreciated. Thank you.
I just made some minor adjustments, you may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} /param1
RewriteRule ^(.*)(param1)/([^/]*)/([^/]*)/([^/]*)$ http://example.com/$1$2.php?$2=$5&$3=$4 [L,R=301]
I'm trying to match a a bunch of redirects for my website with basically moved to a different folder on the server. I need to make http://www.site.com/index.php?page=anypage go to http://www.site.com/newfolder/index.php?page=anypage. The thing is http://www.site.com/index.php and http://www.site.com/index.php?page=home should remain untouched. How can I accomplish this?
I was trying the following in the .htaccess file, but I am affraid to make a mistake. I really don't know how to test this, either.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/index.php?page=(.*)$ http://www.site.com/newfolder/index.php?page=$1 [R=302,NC]
RewriteRule ^/index.php?page=home http://www.site.com/index.php?page=home [R=302,NC,L]
Now I figured that this is temporary, so I should know ho to reverse it! The next week, the links will have to redirect again to the root server. Also, what should I do to re-establish the normal redirection??
If I've followed your scenario correctly, you want something like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{QUERY_STRING} !page=home
RewriteRule ^index.php /newfolder/index.php [R,L]
As far as testing goes, I prefer to try rules out on a local test server. If you have full control over the server (as is the case locally), there are some mod_rewrite directives that help you log what's going on, and that can be helpful in debugging. The module documentation has more information about this.
Edit: When you want to switch back, modify the RewriteRule above like so:
RewriteRule ^newfolder/index\.php /index.php [R,L]