I am using this rule now and it is applied to my members...
RewriteRule ^member/([0-9]+)/([^.]+).html$ member.php?id=$1&name=$2
And it is looking like this:
http://www.mysite.com/member/1/Foo_Smith.html
I want to take this further and deeper into the site like this:
http://www.mysite.com/member/1/Foo_Smith/Gallery.html
http://www.mysite.com/member/1/Foo_Smith/Gallery/viewPhoto/nice_picture_i_took.hmtl
Pages in my root is galleri.php and viewPhoto.php
Any ideas if this is possible and any examples on how to achive this?
Best regards, Joakim
RewriteRule ^member/([0-9]+)/([^./]+)\.html$ member.php?id=$1&name=$2
RewriteRule ^member/([0-9]+)/([^/]+)/Gallery\.html$ gallery.php?id=$1&name=$2
RewriteRule ^member/([0-9]+)/([^/]+)/Gallery/viewPhoto/([^/]+)\.html viewPhoto.php?id=$1&name=$2&photo=$3
I haven't tested it, but I think it should work.
Related
I have below url(s)
www.localhost.com/profile.php?username=first.last
i would like to permanently redirect above url to using .htaaccess file. (apache server)
www.localhost.com/first.last
please also consider there are few other urls there but i dont want to touch them..like
www.localhost.com/message.php?id=12
www.localhost.com/editprofile.php?editname=first.last
www.localhost.com/uploadphoto.php?username=first.last
can anyone please help me.
thank you in advance.
You could try to handle the Query String with RewriteCond and pass the captured match to RewriteRule. You must exclude any .phpscripts of your rewriting rule otherwise it will create some problems with others URLs.
Don't forget to add the [QSA] tag after your RewriteRule otherwise it will not add the Query String parameters.
Maybe doing something like this:
RewriteEngine on
#serve any existing php scripts as usual
RewriteRule ^([a-zA-Z0-9]+\.php) - [L]
#and now handle your specific stuff:
RewriteCond %{QUERY_STRING} ^([a-zA-Z0-9]+\./[a-zA-Z0-9]+)$
RewriteRule ^(%1)$ /profile.php?username=%1 [QSA]
I don't test it but it should be a good beginning. You can read some good stuff here and inside the docs for mod_rewrite httpd 2.2 about how to write and handle specific rewriting use cases.
I'm trying to use mod_rewrite to point the blog portion of a site to a blog site.
this is what I have to handle the normal stuff
RewriteRule ^(\w+)/?$ index.php?page=$1
This is what i'm trying to use for the blog site
RewriteRule ^blog/?$ http://url.to.my.blogger.site
but it's not working, when I go to site/blog it directs me to index.php?page=blog is there something I need to do to not do the second rewrite if the first is correct? like an if/else? sorry don't know much about mod_rewrite so any advice would be awesome.
also I noticed that if I try to do something like site/home everything works fine but if I attempt to hit site/home/ it puts all of my urls into the wrong context, for example my css and images don't get loaded correctly.
my full file is this
RewriteEngine on
RewriteRule ^blog/?$ remote/blog/uri/here
RewriteRule ^(\w+)/?$ index.php?page=$1
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php - [F]
and when i hit site/blog it still tries to serve index.php?page=blog, I'm guessing I have to break out of the code at some point? I couldn't find documentation on if/else statements
I needed to add flags to my RewriteRule lines so that the server wouldn't evaluate further. Changing them to be
RewriteRule ^/blog http://url.to.blog [L]
did the trick, the problem was that it was evaluating all the way down, seeing as I wasn't attempting to go to index the last valid rule to evaluate was the general rewrite rule.
I am currenctly facing some htaccess/rewriterule issues. (And I am new to this area)
Let's assume we have an url like this:
http://mypage.at/very/cool
The URL is supposed to look like this (Cause I am using an AJAX-loadedContent which requires this):
http://mypage.at/#ajx/very/cool
So I would like to add the part '#ajx' to every url which does not already contain it.
Which means if an url does already look like: http://mypage.at/#ajx/so/pretty then there is no need for changes.
As I am not sure wheter this creates troubles with the GoogleSearchIndex, I would additionally like to know if there is a way to exclude this rule for searchbots.
Thanks for any help.
Ripei
Since you reported that this does not work (which is probably because your version of Apache doesn't support Perl-style RegEx):
RewriteRule ^(?!#ajx)(.*)$ http://mypage.at/#ajx/$1 [L]
I think this should do it:
RewriteCond %{REQUEST_URI} !^/#ajx
RewriteRule ^(.*)$ http://mypage.at/#ajx/$1 [L]
EDIT: After trying this myself and reading around on the Internet, I'm not sure this is actually possible. A pound sign (#) is not a legal part of a URL. This answer comes close, but I'm going to have to leave this to somebody who knows more to say whether this can even be done the way #Ripei asked for.
Something like this might work:
RewriteCond %{REQUEST_URI} !^/#ajx
RewriteRule ^(.*) http://%{SERVER_NAME}/#ajx$1 [R,L]
Hah finally after lot's of reading and testing - I got it.
RewriteCond %{REQUEST_URI} !^#ajx
RewriteRule . /\#ajx%{REQUEST_URI} [L,R,NE]
This Code works for me... don' ask me why this one is working, to be honest I do not have a clue! But well I am fine with the fact, that it IS working :)
I absolutely do not understand mod rewrite or the syntax to make it work. I have however managed to cobble together the following, which works exactly as I need it to on my site:
RewriteRule ^page/([^/\.]+)/?$ page.php?page=$1 [L]
it changes www.mysite.com/one into www.mysite.com/page.php?page=one
wonderful.
However, is there a way that I can add an exception to the rule, so that if I try to use the url www.mysite.com/feed for example, it will go to www.mysite.com/feed/index.php rather than trying to redirect to www.mysite.com/page.php?page=feed
Thanks in advance!!
There are a couple of ways you could do this. Probably best would be to add a RewriteCond above the RewriteRule. Something like this (untested):
RewriteCond !^feed
RewriteRule ^page/([^/\.]+)/?$ page.php?page=$1 [L]
If you can't get that to work then you could also put a different RewriteRule above your one to redirect before this rule is matched...
I am trying to use mod_rewrite to pretty up a URL.
I want the URL to look like this:
http://example.com/bart/school?page=2
and the rewritten URL to be:
http://localhost:8080/app?user=bart&tag1=school&page=2
If possible, I would also like to be able to have more than one tag per user:
http://example.com/bart/school/lisa?page=2
Would look like:
http://localhost:8080/app?user=bart&tag1=school&tag2=lisa&page=2
I far as I can tell this is possible by using mod_rewrite but I can't seem to figure it out. Any help would be really appreciated!
For the single tag use the following:
RewriteCond %{QUERY_STRING} ^page=([0-9]+)$
RewriteRule ^([^.]+)/([^.]+)$ http://localhost:8080/app?user=$1&tag1=$2&page=%1