I've been trying things on my server but I can't figure out what's going wrong.
As of now, this is the .htaccess I have:
Options +FollowSymlinks
RewriteEngine on
RewriteRule (.*) $1 [NC, L]
Instead of rewriting to 'match' it rewrites to 'match'.php
Any idea why?
The MultiViews option can cause such a behavior. Try to disable it.
Related
For some reason Apache doesn't rewrite my URL's and I can't figure out what's wrong.
I can confirm that mod_rewrite works because this works:
RewriteEngine on
RewriteRule ^oranges.html$ apples.html
And it shows the apples.html page.
I am trying to use this but it doesn't do anything!
Options -Multiviews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)[/]*$ index.php?page=$1
To look like this: http://example.com/search/
What could be wrong here? :o
I have a single blog.php page that should get redirected from all these requests:
www.site.com/blog #goes to blog.php
www.site.com/blog/id-of-an-entry #goes to blog.php?id=id-of-an-entry
Also internationalised versions such for french:
www.site.com/fr/blog *# to blog.php?lang=fr
www.site.com/fr/blog/id-of-entry* #to blog.php?lang=fr&id=id-of-entry
What would be the more eficient and effective cond/rules for .htaccess? I've made many attemps but end walking in circles or with to many specialised rules :-) Thanks for any insights!
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 ^blog/([^/]+)/?$ /blog.php?id=$1 [L,NC,QSA]
RewriteRule ^blog/?$ /blog.php [L,NC,QSA]
RewriteRule ^([^/]+)/blog/([^/]+)/?$ /blog.php?lang=$1&id=$2 [L,NC,QSA]
RewriteRule ^([^/]+)/blog/?$ /blog.php?lang=$1 [L,NC,QSA]
I am not using this regulary so there can be better way but this could help you. Rules works like this. In () are your variables which corresponds to what you want to match. Than you can refer to them by $1 and so on. For example news/local would redirect them to file news-local.php you can use the same system to match you get variables.
RewriteRule ^([a-z]+)/([a-z]+)$ $1-$2.php
Need some help with a rewrite please.
I have domain http://www.example.com. There are multiple folders within the root. I'd like to rewrite http://www.example.com/folder1/public/index.php to http://www.example.com/folder1
I dont have access to the main apache config so i'll need to do this in a .htaccess. If possible I'd also like to place the .htaccess inside folder1, not in the root.
Any help would be awesome, thanks.
Thinking monkey is close. Try:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /folder1
RewriteRule ^(?!public/)(.*) public/$1 [L]
You need the RewriteBaseand you need to stop recursive evaluation of the rule. The (?!public/) bit just means don't match anything already starting with public/. You need this sort of guard in .htaccess rules.
I presume you are trying to redirect any request to folder1 to folder1/public.
By that I mean, you want your URLs to look like http://www.example.com/folder1 while the actual URL will be http://www.example.com/folder1/public/index.php.
First of all, you have to use http://www.example.com/folder1 in your hrefs and rewrite this to http://www.example.com/folder1/public/index.php.
Add the below to your .htaccess residing in your folder folder1.
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
I have this address
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
that I would like to make it a lot shorter and more SEO friendly to something like (I don't know ... open to suggestions) http://www.nfrases.com/tag/10/508 or http://www.tag10name.nfrases.com/508
I need help with how to code this, because a simple thing as trying to make the address always http://www.nfrases.com case the user goes to http://nfrases.com or www.nfrases.com I tried and failed :(
Used this code by the way:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301]
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
becomes
http://www.nfrases.com/10/508
with this in your .htaccess
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^([0-9]*)/(.*)/?$ /tag.php?id_tag=$1&id_frase=$2 [L,QSA]
Untested. Let me know if it works for you.
Can anyone spot what is wrong with this URL rewrite? I can't get it to pass anything to GET (the script loads, but no parameters are passed):
RewriteRule ^archive(/(.*))?$ archive.php?action=$1 [QSA,L]
I want to map "archive/browse/" to "archive.php?action=browse".
You can get some conflicts when MultiViews is enabled. If it’s enabled, Apache first tries to find a file with a similar name to map the request to before passing it down to mod_rewrite. So a request of /archive/browse/ ends in /archive.php/browse/ before mod_rewrite can map it to your /archive.php?action=browse.
Try to disable it with:
Options -MultiViews
RewriteEngine On
RewriteRule ^archive/(.*)$ archive.php?action=$1 [QSA,L]
Would rewrite anything after /archive/ to archive.php?action=test/dir/path
RewriteRule ^archive/([^/]*) archive.php?action=$1 [QSA,L]