I have made a fake directories to show specific content using this line
RewriteRule ^service/online/$ service.php [L]
The issue is it works fine if the URL is like this
www.site.com/service/online/
But if the URL is like this
www.site.com/service/online
it wont work
is there any command to make it work in both scenarios.
Use:
RewriteRule ^service/online/?$ service.php [L]
Related
I am trying to change my url through .htaccess in the following way
Original URL: http://www.example.com/latest-news.php?id=2/topic=testing
Rewritten URL:http://www.example.com/2/testing
Rule for .htaccess
RewriteRule ^([^/]*)/([^/]*)$ /latest-news.php?id=$1&topic=$2 [L]
This is working fine but the other files which are existing in a folder are not opening. The url is opening as www.example.com/testing/foo.php but content of the page is of http://www.example.com/2/testing
Can you try with a similar rule like the one bellow?
RewriteRule ^([0-9]+)/([a-zA-Z])$ /latest-news.php?id=$1&topic=$2 [L]
Can't really test it on my server but you can adapt it to suit your needs
RewriteEngine On
RewriteRule ^([0-9]+)/([^/]*)$ /latest-news.php?id=$1&url=$2 [L]
Since second part consists characters and digits So I modify the answer of stoica. Thanks #stoica
I am trying to create a rewrite in my .htaccess file for my wordpress site. I need
www.a3performance.com/fastestsuit
to point to
http://www.a3performance.com/legend-fastest-racing-suit/
I am trying this, but it doesn't seem to work?
RewriteRule ^fastestsuit/?$ legend-fastest-racing-suit [NC,L]
Seems that you need to use here Redirect from one folder to new folder.
Something like this:
RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L]
Actually #labris idea worked. For some reason it took a bit for my server to register the .htaccess change.
RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L]
I am working locally on Windows 7 with wamp server (v2.5). I have one working rewrite rule for the main front controller in my project, like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [NC,L]
It successfully strips .php from the queries. From this main front controller index.php I have a link to another front controller named theme.php, where I use menu links w/o the.php file extension, like this:
theme/regions
in stead of
theme.php/regions
For that to work I need to add a second rewrite rule to add the php exension, like so:
RewriteRule ^theme($|/$) theme.php/$1 [NC,L]
The only thing I get is a 404 page though :-(.
I would be very grateful for some hints on how to go about this.
You need to put your theme rule before the general route to index.php. And you need to reference what comes after the /theme/ so something like:
RewriteRule ^theme(/?.*)$ theme.php$1 [L]
Additionally, this rule won't work if you have Multiviews turned on, but, this is actually something that's perfectly suited for Multiviews anyways, so you could just try turning that on instead of using a rule to rewrite theme:
Options +Multiviews
Your second RewriteRule works independently of the others and should be placed above the others in your question.
In addition, the format is wrong - you don't need to capture or append anything.
RewriteRule ^theme/?$ theme.php [NC,L]
This will be a common question however I cannot get this to work at all and have been pissing around with it for hours now.
What I need to do is have this url domain.com/landing/subdirectory/index.html appear as domain.com/subdirectory.
This will only be used for the one file so I don't need anything fancy, everything I have tried just doesnt seem to work. I'm so used to it being easy peasy to do within a framework like yii with proper routing set up but cant seem to figure it out in raw .htaccess >.<
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+landing/subdirectory/(index\.html)?($|\ |\?)
RewriteRule ^ /subdirectory [L,R=301]
RewriteRule ^subdirectoy/?$ /landing/subdirectory/index.html [L]
I have a website where if I go to the URL http://mysite.com/community it shows page not found. But, the URL http://mysite.com/community/ correctly displays the page. How can I set up a rewrite for that "/" after community?
This is my present .htaccess:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^admin$ Admin/index.php?qstr=$1 [L]
RewriteRule ^(.*)/$ index.php?qstr=$1 [L]
These were the ones tried by me, but failed
First,
RewriteRule ^(.*)/community $1/community/ [L]
second,
RewriteRule /community /community/ [L]
All with different combinations of with and without [L].
From the Apache URL Rewrite Guide:
Trailing Slash Problem
Description:
Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then the server searches for a file named foo. And because this file is a directory it complains. Actually it tries to fix it itself in most of the cases, but sometimes this mechanism need to be emulated by you. For instance after you have done a lot of complicated URL rewritings to CGI scripts etc.
Solution:
The solution to this subtle problem is to let the server add the trailing slash automatically. To do this correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If we only did a internal rewrite, this would only work for the directory page, but would go wrong when any images are included into this page with relative URLs, because the browser would request an in-lined object. For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the external redirect!
So, to do this trick we write:
RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R]
The crazy and lazy can even do the following in the top-level .htaccess file of their homedir. But notice that this creates some processing overhead.
RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
Well, after trying out all the above solutions as well as some of my own, I finally solved this. I'm definitely sure that this is NOT a complete solution but it sure solved it for the time being.
Solution: Just created an empty directory named "community" in the root folder. That's it!
But I'm still on the lookout for the actual solution to this.