.htaccess modrewrite friendly url - .htaccess

I've searched on Google to find a way to make my URL friendly to my users.
My url now is this:
http://www.rasolutions.nl/blogitem?id=2&name=newpages
I would like it to be like this:
http://www.rasolutions.nl/blogitem/2/newpages
I used Google to find something like that, my result:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^blogitem/([0-9]+)-([a-z]+) http://rasolutions.nl/blogitem?id=$1&name=$2 [NC]
Sorry for the bad English, I'm Dutch and my English isn't the best.
Thanks for the help.

You can write in your .htaccess some think like:
RewriteEngine on
# ! Warning !
RewriteCond %{REQUEST_FILENAME} !/cms/base/tools/urlmodifier.php$
RewriteRule ^(.*)$ /cms/base/tools/urlmodifier.php?param=$1 [L,QSA]
... and do redirect in urlmodifier.php with including of file from request url and modifications of $_SERVER['REQUEST_URI'].

Related

Transform(redirect) URL segment to a GET parameter

I know this has probably been answered but I can't find anything specific to my issue.
I have URLS like this:
https://staging.books.co.za/travelguide/route-map/SAFI546754
https://staging.books.co.za/travelguide/route-map/SAFI189444
https://staging.books.co.za/travelguide/route-map/SAFI978634
and I need them to be redirected to URLS like this:
https://staging.books.co.za/travelguide/route-map?reference=SAFI546754
https://staging.books.co.za/travelguide/route-map?reference=SAFI189444
https://staging.books.co.za/travelguide/route-map?reference=SAFI978634
Please help...What would the rule look like in my .htaccess file???
This should do the trick:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^travelguide/route-map/(.+) /travelguide/route-map?reference=$1
See here for a demo http://htaccess.mwl.be?share=6c2be57a-6bb7-5083-9122-aaf63162b240
Try and use this in your .htaccess:
RewriteEngine On
RewriteRule ^travelguide/route-map/([-a-zA-Z0-9_]+)/?$ route-map?reference=$1 [L]
Make sure you clear your cache before testing this.

How to rewrite url for certain pages in htaccess?

I am trying to show different url and redirect users to specific url with .htcaccess when they click on a blog post but to no avail.
Lets say the url is: http://localhost/mySite/article.php?article_title=test-title
then I would like to show it as http://localhost/mySite/article/test-title
This is my current htcaccess file:
#turn on url rewriting
RewriteEngine on
#remove the need for .php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
#rewrite rule for blog
RewriteRule article/([A-Za-z0-9-]+) /mySite/article.php?article_title=$1
But for some reason it is not redirecting/showing the correct url. I am not getting any errors.
EDIT
Trying to ask my question again and explain it better. Let's say the url is
http://localhost/www.example.com/admin/editUser.php?user_id=126
and I would like to rewrite the url like this:
http://localhost/www.example.com/admin/user/126
then how can I achieve this. I tried using this website to check the modified url but it does not work. Seems like it does not work with any of the accepted answers here in stack at all.
This is my htaccess file atm. It is in the root of www.example.com
#turn on url rewriting
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^user/([0-9]+)/?$ /editUser.php?user_id=$1 [NC,L] # Handle user edit requests
Apache Module mod_rewrite is enabled. Also added an alias. Still no changes in the url. If I try something really basic like this:
# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]
it works fine.
Why is the users redirect not working? What am I doing wrong.
Try it like this for your rule for article url in mysite directory.
RewriteRule ^article/([A-Za-z0-9-]+)$ article.php?article_title=$1 [QSA,NC,L]
you need to mention start ^ and end $ of string.

How can I redirect hits to a querystring URL via HTACCESS

I've created a website with a decent WordPress theme and framework about events but there's some links to a pretty annoying page like this:
/?event-category=gigs
I would like to redirect any links to URLs like that simply to:
/gigs
I'm hopeless in Htaccess, can someone suggest the syntax please? I'd appreciate it.
You can use this rule just below RewriteEngine On line:
RewriteCond %{QUERY_STRING} (^|&)event-category=(gigs) [NC]
RewriteRule ^ /%1? [R=302,L,NE]

Ho to make .htacess redirect and keep full url path

Hi i would like ask you about .htacess 301 redirect:
I have many dynamic urls with paths for example like this:
http://www.domain.com/post1.html
http://www.domain.com/post2.html
and i need to redirect it to the same url but with little bit different domain (without WWW):
http://domain.com/post1.html
http://domain.com/post2.html
I have done like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Redirect works, but my normal urls becomes urls with ID's like:
http://domain.com/index.php?id=931
not like it should be:
http://domain.com/post1.html
Any ideas or helo are appreciated.
Thank you.
You have some other rewrite rules happening here obviously, but with what you've given us, you could try adding this before your rules in order to get it to stop processing an URL which has been rewritten as such:
RewriteCond %{QUERY_STRING} id=[0-9]+
RewriteRule ^index.php - [L]

.htaccess php to html

sorry for this simple question, however i still cant get my head round using .htaccess
I'm trying to convert:
search.php?s=dvd&page=1
to
/Search/dvd/page1.html
Thanks,
Jack
I think something like:
RewriteRule ^search/([A-Za-z]+)/page([0-9]+)\.html$ search.php?$1&page$2
Should do the trick.
Further reading here: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
you must put your link "/Search/dvd/page1.html" in the page and with htaccess it will convert to the "search.php?s=dvd&page=1" . i hope it be usefull :)
sample correct htaccess code :
RewriteEngine On
RewriteRule Search/(\d+)/page?(\d+)\.html$ search.php?s=$1&page=$2 [NC,L]
If I understand the question OP wants to convert php to html redirection. Try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
# to match /search.php?s=dvd&page=1
RewriteCond %{QUERY_STRING} ^s=([^&]*)&page=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%1/page%2.html? [R,L,NC]
# to match /search.php?page=12&s=dvd
RewriteCond %{QUERY_STRING} ^page=([^&]*)&s=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%2/page%1.html? [R,L,NC]
R=301 will redirect with https status 301
L will make last rule
NC is for no case comparison
%1 and %2 are the query parameter values
I think you want make clean URI, so if user type url like this:
search/televisi/page4.html
it same as like search.php?s=dvd&page=1
Add this code:
RewriteEngine On
RewriteRule ^search/([a-z]+)/page([1-9]+).html$ search.php?s=$1&page=$2

Resources