I have a profile.php?id= page, I turn it into profile/id with this RewriteRule RewriteRule ^profile/([A-Za-z0-9-\/]+)/?$ profile.php?id=$1 [NC,L]
Right now I'm trying to set a page to contact the user so I create a contact-profile.php?id=
I want to make an URL like that profile/user-id/contact but I'm stuck.
I tried to do this RewriteRule ^profile/([A-Za-z0-9-\/]+)/?$/contact contact-profil.php?id=$1 [NC,L] but it doesn't work. The problem is that I don't know how to pass this fake /directory after my /user-id variable.
Try this,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/([\w-]+)/contact$ contact-profile.php?id=$1 [L]
Related
I've been trying to get a better URL format than the regular one. I have to deal with parameters, and I'd like to get from :
http://www.whatever.com/embed.php?site=site1&id=videoid
to :
http://www.whatever.com/embed/site/site1/id/videoid
I've been trying to get something like this using .htaccess, but I still don't understand how it really works.
This is what I have for now :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^embed/(.*)/(.*)$ /embed.php?site=$1&id=$2
The three first lines actually hide the .php extension, which is okay, but the next one doesn't work as I wish it would !
Any one as an idea ?
Thanks in advance guys !
Try it,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^embed/site/([\w-]+)/id/([\w-]+)$ embed.php?site=$1&id=$2 [QSA,L]
I have such urls:
http://site.ru/ontent/wefwefw/article.php?article=369-tayskaya-kuhnya-recept-s-foto
http://site.ru/ontent/wefwefw/article.php?article=32237-ogurci-recepti-na-zimu
http://site.ru/ontent/wefwefw/article.php?article=90-ogurci-na-zimu-recepti-po-koreyski
I want to rewrite tham like:
http://site.ru/tayskaya-kuhnya-recept-s-foto.html
http://site.ru/ogurci-recepti-na-zimu.html
I tried smth like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ontent/wefwefw/$1 [L]
But how cut unnecessary parts of string?
Unless article.php is able to derive the right article from the title alone, what you want to do is not possible. mod_rewrite is good at rewriting things, but it can't summon an article-id from thin air if it isn't in the original request. You would have something like:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)\.html$ ontent/wefwefw/article.php?article=$1 [L]
When you would request http://site.ru/tayskaya-kuhnya-recept-s-foto.html, it will load http://site.ru/ontent/wefwefw/article.php?article=tayskaya-kuhnya-recept-s-foto. Then you have to get the id 369 in some other way based on the title if needed.
The best in this case is:
http://site.ru/369-tayskaya-kuhnya-recept-s-foto.html
redirect to
http://site.ru/ontent/wefwefw/article.php?article=369
with:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+)-[^/]*\.html$ ontent/wefwefw/article.php?article=$1 [L]
I have a URL:
domain.com/abc/hotel_detail.php?id=2
And I want to do a URL re-write to make it look like this :
domain.com/abc/hotel_detail/2
My current .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{QUERY_STRING} ^id=20$
RewriteRule ^abc/hotel_detail/([0-9]+)$ ^abc/hotel_detail.php?id=$1 [L]
The first part contains code for removing the extension(.php) from pages.
When I try to open this link domain.com/abc/hotel_detail/2 , it gives me object not found error.
Can Someone please tell me whats wrong with the code?
Remove this line:
RewriteCond %{QUERY_STRING} ^id=20$
Changing your file to:
RewriteEngine On
RewriteRule ^abc/hotel_detail/([0-9]+)$ ^abc/hotel_detail.php?id=$1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,R]
should work. I removed RewriteCond %{QUERY_STRING} ^id=20
Your first rewritecond and rule was overwriting the second one, switching them around should fix it.
I think this should work
RewriteRule ^abc/hotel_detail/([0-9]*)$ abc/hotel_detail.php?id=$1 [L]
([0-9]*) miltiply sign.
and the ^ for the real link
Here is my .htaccess :
RewriteEngine on
RewriteBase /site
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^([a-z]+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&u=$3 [L]
I am trying to have short urls in this manner
if someone goes to www.mysite.com/johndoe htaccess sends him/her to this link index.php?a=profile&u=johndoe
what would be the best way to do this? I did read htaccess tutorials and tried different ways and failed :/
Try inverting the condition and remove the rewrite base:
RewriteEngine on
RewriteCond %{request_filename} !-f
RewriteCond %{request_filename} !-d
RewriteRule ^([^/]+)/?$ /index.php?a=profile&u=$1 [L]
This will make it so:
if someone goes to www.mysite.com/johndoe
The "johndoe" gets matched by ^([^/]+)/?$ and backreferenced by $1, resulting in:
this link index.php?a=profile&u=johndoe
I have url
http://www.domain.com/folder/?variable=1
i would like to do a mod redirect to index.cfm with the folder going in as path variable and the variable as the second variable.. the first three lines work with my site, i am having trouble with the last bit
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.cfm?path=$1 [L]
RewriteRule (.*)\?(.*)$ /index.cfm?path=$1&$2 [L]
thanks
You need to add QSA (or qsappend) flag, like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.cfm?path=$1 [L,QSA]
This will make mod-rewrite append any original query-string to the sub-request.
I had problems redirecting a URL with a ? in it.
The url was like: /index/slug_with_questionmark?.html
The solution that works for me:
RewriteRule ^index/slug_with_questionmark(.*) http://yourdomain.com/newurl? [R=301,L]
Pay attention to the ? at the second statement. This one fools the browser so it redirects it nicely.