I'm sure that's been asked zillions times but i can't get it to work,
i'm trying to rewrite a url with querystring, my url is for example:
http://example.com/articles/index.php?keyword=book
and i want to be accessible from
http://example.com/articles/keyword/book/
I google it and i didn't have any luck,
am i on the right track? i got this:
RewriteCond %{QUERY_STRING} ^keyword=(.*)$ [NC]
RewriteRule ^/articles/index.php$ /articles/keyword/$1 [NC,L,R=301]
UPDATE
this is working fine
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteRule ^.*/(\w+)\b$ /articles/index.php?keyword=$1
It should work:
RewriteRule ^articles/keyword/(.*)/?$ index.php?keyword=$1
If not, please tell me ;)
Related
I am actually trying to have the URL repointed via HTAccess using the Old Formating of the website:
https://fw1.work/actualites/details.php?ID=3191
to the new Formating. To do so I need to point it to the New URL Formating:
https://fw1.work/actualite.php?id=3191
Actually tried a couple of things online but nothing seems to be working the way I want it...
RewriteCond %{QUERY_STRING} ID=(\w+)$
RewriteRule ^actualites/details.php /actualite.php?id=%1 [L]
This is where I am at actually.
make sure rewrite mod enabled,
then let RewriteRule rgexp match the full url.
RewriteEngine On
RewriteCond %{QUERY_STRING} ID=(\w+)$
RewriteRule ^actualites/details.php(.*) /actualite.php?id=%1 [L]
You need to write the rules as follows :
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} id=(\w+)$
RewriteRule ^actualite.php$ actualites/details.php?ID=%1 [L]
I know that this site has many questions about URL rewriting. But as a newbie, I could not find the correct answer for my case.
My question is: I would like to rewrite the original URL like this: when user visit:
http://username.example.com/a/b/c/d/e/f/g/h...
the apache will process request as
http://example.com/index.php?user=username&a=b&c=d&e=f&g=h...
According to what I knew, the solution could be using QUERY STRING, but I don't know how to do that.
Any help will be appreciated! Thanks,
The first thing you need for this is to create Dynamic sub-domain. create dynamic subdomain link will help you in this. Use following config for your case:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteRule ^([aA-zZ])$ index.php?user=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.example.com
RewriteRule (.*) index.php?user=%1
once this is in place, you can add more conditions for the remaining parameters.
Could someone please tell what I am doing wrong. I have searched through lots of posts here and elsewhere about doing this.
Just want to make localhost/index.php?page=somepage look like localhost/somepage
Here is what I have so far:
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z\-]+)$ index.php?page=$1
</IfModule>
Not getting any errors, but it's not dong anything actually. Maybe I have the code right but just can't do this on my system. But would like a pro opinion.
Thank you.
Maybe worth mentioning: have htaccess file in root dir, all pages are in a folder named "pages" and all end in .htm
That looks like it takes a request like: localhost/somepage and internally rewrites it to localhost/index.php?page=somepage, which is really what you want. But it doesn't address if someone tries to go to localhost/index.php?page=somepage. In order to address that, you don't want to rewrite URL's, you want to redirect the browser to a new URL:
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^\ \&]+)
RewriteRule ^ /%1? [L,R]
I have this code and I used a generator but it isn't working.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^chrisbrighton\.co\.uk$
RewriteRule ^(.*) http://chrisbrighton.co.uk/$1 [R=301,L]
RewriteRule ^iPhone5s.php /reviews/iphone/5s [L,R=301]
I'd like my URL to go FROM:
http://chrisbrighton.co.uk/iPhone5s.php
TO:
http://chrisbrighton.co.uk/reviews/iphone/5s/
Why isn't this working? The page doesn't load.
P.S: I have looked at other questions but as I don't understand it I need to provide my own code.
Thanks.
You are rewriting in reverse order, try this?
RewriteEngine On
RewriteBase /
RewriteRule ^iPhone5s.php /reviews/iphone/5s [L,R=301]
Rewrite rule FROM TO, you've messed TO with FROM
I know this question may have been asked many times before and I may be down-voted a lot but trust me, this was my last resort after testing and reading many articles on google.
I have the url /index.php?action=gametypes&mode=control-point which I would like to rewrite to /gametypes/control-point.
I've tried
RewriteEngine On
RewriteRule ^gametypes/([^/\.]+)/?$ index.php?action=gametypes&mode=$1[L]
Now when I visit /gametypes/control-point I get a 404 not found and the URL shows rewrites to localhost/thecoremc/gametypes/control-point/index.php. It's a 404 because there is no index.php. Any idea what I could use to successfully load the page?
Extra info: I'm running my localhost with the domain localhost/thecoremc/ and apache 2.4.4
Thanks!
You could try this instead...
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?action=$1&mode=$2 [L]
I used a dummy-domain, which was http://www.domain.com/index.php?action=gametypes&mode=control-point to achieve this.
Based on your comment, try this...
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /thecoremc/index.php?action=$1&mode=$2 [L]
which is based on: http://localhost/thecoremc/index.php?action=gametypes&mode=control-point
You can use this code in your /thecoremc/.htaccess file:
RewriteEngine On
RewriteBase /thecoremc/
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&mode=$2 [L,QSA]
Try this. This might be helpful for your work.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)&name=(.*)$
RewriteRule ^articles\.php$ /article/%1/%2? [R=301]
RewriteRule ^article/([^-]+)/([^-]+)$ /articles.php?article_id=$1&article_name=$2 [L]
The above code will redirect
localhost/a1/articles.php?id=10&name=xyz
to
localhost/article/10/xyz
Try this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule gametypes/(.*)/(.*)/ index.php?action=$1&mode=$2