How would I write a redirect rule that would let me use both http://www.site.com/rss and http://www.site.com/anydirectory/rss rather than http://www.site.com/rss.xml and http://www.site.com/anydirectory/rss.xml ?
I think I'm close, but for some reason, it's a Monday.
RewriteRule ^(.*)/rss.\xml/$ $1/rss [L]
I think this is what you want (you have them reversed):
RewriteRule ^(.+/)?rss$ $1rss.xml [L]
This is a guess, but it looks like you intended to escape the . and that is done with \. instead of .\
RewriteRule ^(.*)/rss\.xml$ $1/rss [L]
It sounds like you have the XML files, and you want to make URIs without the XML extension work.
# translate /rss to /rss.xml
RewriteRule ^rss$ /rss.xml
# translate /anydirectory/rss to /anydirectory/rss.xml
RewriteRule ^(.+)/rss$ /$1/rss.xml
The code you tried suggests the opposite.
# translate /rss.xml to /rss
RewriteRule ^rss\.xml$ /rss
# translate /anydirectory/rss to /anydirectory/rss.xml
RewriteRule ^(.+)/rss\.xml$ /$1/rss
Related
Ok, im pretty new at this and I would really appreciate some help, thanks!
How can i rewrite this in .htaccess correctly?
So I have a query string in my url:
/?url=contact
All i want to do is remove the query string
/contact
Help? I scoured google and I'm learning the syntax right now, but the fact remains..I dont know how to do it just yet. Thanks to all
This was my solution:
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Try this:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]
To a user on your site, they will see and navigate to this:
http://example.com/contact
But the real page would be something like this:
http://example.com/index.php?url=contact
This bit, [L], tells the server that this is the last line of the rewrite rule and to stop.
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule index.html %1
(or whatever if it's not index.html, index.php, whatever)
You need to capture the query string, which is not looked at by RewriteRule normally, and use the %1 back reference, not $1 as you would in a capture in a RewriteRule
Before: https://example.com/index.php?user=robert
RewriteEngine On
RewriteRule ^user/([^/]+)?$ index.php?user=$1 [L,QSA]
After: https://example.com/user/robert
I want to rewrite my url but i cant do proper way.
mysitename.net/index.php?title=Category:Public_Companies&pagefrom=8
To :
mysitename.net/Category:Public_Companies/8
How can i do that.
If you have other pages than Category, I recommend to use this:
RewriteRule ^Category:(.+)/(.+)$ /index.php?title=Category:$1&pagefrom=$2 [L]
Otherwise, use this:
RewriteRule ^(.+)/(.+)$ /index.php?title=$1&pagefrom=$2 [L]
hi i am trying to make clean and neat url using rewrite rule
I want to achive :
abc.com/t/param1/param2
Rewite rule that I wrote
RewriteRule ^t/(.+)/(.+)$ t/index.php?v=$1&t=$2 [L]
but it doen't work it redirects to :
http://abc.com/?v=param1&t=param2
Your regex should only match characters that aren't slashes. So your rule should look like
RewriteRule ^t/[^/]+/[^/]+$ t/index.php?v=$1&t=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/$ /?v=$1&t=$2 [L]
I have the following code in the my .htaccess file and the top Rewrite works fine the bottem one does not I know why but I dont kno how to fix it.
Its seeing RewriteRule ^([^/]*).html index.php?p=order&course_id=$1 [L] as the top rewrite command becuase of the hightlighed part and i dont want to put it in a dir
RewriteEngine on
RewriteRule ^([^/.]+).html
index.php?p=$1 [L]
index.php?p=about_us
RewriteRule ^([^/]+).html
index.php?p=order&course_id=$1 [L]
index.php?p=order&course_id=5
Thank you,
Can you give example urls that should match the pattern block and what you would like them to be rewritten to? That would be very helpful.
One thing I notice is that your first regexp you test if you match the pattern block with a + which means 1 or more times and the second one you check it with a * which means 0 or more so I don't think the second one will ever be called, although I am very new to regexps but it is just something I noticed.
These are very helpful resources for me:
http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
http://forum.modrewrite.com/
From the example of the urls you would be using, this should work:
# http://website.com/about_us/ rewrites to /index.php?p=about_us
RewriteRule ^([0-9a-z_-]+)/?$ index.php?p=$1 [NC,L]
# http://website.com/order/12/ rewrites to /index.php?p=order&course_id=12
RewriteRule ^order/([0-9]+)/?$ index.php?p=order&course_id=$1 [NC,L]
The second Rewrite might be:
# http://website.com/order/12/ rewrites to /index.php?p=order&course_id=12
RewriteRule ^([0-9a-z_-]+)/([0-9]+)/?$ index.php?p=$1&course_id=$2 [NC,L]
Depending on your page structure.
What is wrong with this rewrite rule?
RewriteRule ^api/(.+)$ api/index.php?url=$1 [L]
I simply want "index.php?url=" to be added after api/ and before the rest of the get parameters.
api/image/upload&arg1=1&text=lorem+ipsum
to
api/index.php?url=image/upload&arg1=1&text=lorem+ipsum
What is wrong with (.+) to get everything after api/?
The regex on the RewriteRule is only run against the path part of the URL, not the query parameters. Fortunately there is the [QSA] flag to preserve existing query parameters.
Are you doing something to stop infinite recursion?
RewriteRule ^api/(.+)$ api/index.php?url=$1 [R=301,L]
or some equivalent
I think you must write your domain name before the regex stuff. Like this:
RewriteRule ^(.+).com/api/(.*)$ "$1.com/api/index.php?url=$2" [R=301,L]