URL Rewrite using htaccess for one variable - .htaccess

My url is
domain.com/?p=slide&op=1
here i rewrite domain.com/slide using
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?p=$1
I don't want to rewrite op=1, it should work when i enter
domain.com/slide?op=1
Any help would be appreciated!.

Sounds like you're looking for the QSA flag.
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?p=$1
Will make it so that any query string is kept and appended to the new URL.

Related

How to rewrite a long URL with numerical value to short url with same value

Please Help with non-stardart Long URL
http://example.com/media/player/player.swf?f=http://example.com/media/player/config.php?vkey=12345
Want rewrite to short URL
http://example.com/embed/12345
I assume you mean it the other way around, if someone request http://example.com/embed/12345 you want this internal rewritten to http://example.com/media/player/player.swf?f=http://example.com/media/player/config.php?vkey=12345
If so this works as follows:
RewriteEngine On
RewriteRule ^/?embed/([^/]+)$ /media/player/player.swf?f=http://example.com/media/player/config.php?vkey=$1 [L]
If you really want it the other way around than you have to do it like so:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^f=http://example\.com/media/player/config\.php\?vkey=([^&]+)$
RewriteRule ^/?media/player/player\.swf$ /embed/%1 [L]
If you want a redirect than change [L] to [R=301,L]

Rewrite http://example.com/test.asp?index=3 to http://example.com/about

I need to Rewrite the old urls generated by ISS to a new system we have build (Joomla).
The url's had to be google friendly. What we want to happen:
Rewrite http://example.com/test.asp?index=3 to http://example.com/about
I've used a few Rewrite's i knew, but they dont work:
RewriteRule ^/test.asp?index=3 / [R=301,L]
RewriteRule ^/test.asp?index(.*)3 / [R=301,L
What pice of code am i missing/doeing wrong?
Kind regards.
You must use QUERY_STRING to check query string.
You can use this code in your htaccess (in document root folder)
RewriteEngine On
RewriteCond %{QUERY_STRING} ^index=3$ [NC]
RewriteRule ^test\.asp$ /about [R=301,L]
Note: put this rule before Joomla's rules

Using .Htaccess url redirection

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]

How to make a htacess RewriteRule with a url variable

I want to redirect the url http://www.mywebsite.com/tutos/tutos.php?q=my-tuto/tuto-1.html to
http://www.mywebsite.com/tutos/tutos/my-tuto/tuto-1.html, how to do that with a .htaccess ?
I tried this, but it's don't working... :
RewriteRule ^http://www.mywebsite.com/tutos/([^-]*)$ http://www.mywebsite.com/tutos/tutos.php?q=$1 [L,QSA]
Thanks !
The rule that you have seems to be doing the opposite of what you say that you want. It's redirecting the non-query-string URL to the query-string URL. But if that's what you want, you need to remove the host and protocol from the regular expression. Only the URI (sans query string) is used to match against in a RewriteRule:
RewriteRule ^tutos/([^-]*)$ /tutos/tutos.php?q=$1 [L,QSA,R=301]
But if you wanted it the other way around like you had asked:
RewriteCond %{QUERY_STRING} (.*)(^|&)q=([^&]+)(.*)
RewriteRule ^tutos/tutos.php$ /tutos/%2?%1%3 [L,R=301]

IIS Mod-Rewrite QUERY_STRING/QSA problems

We use IIS Mod-Rewrite from MicoNovae for our IIS rewrites on Windows 2003.
We use the RewriteRule command, for example:
http://www.site.com/section35/page1/tiling-tools/
becomes:
http://www.site.com/search.asp?section=35&page=1&model=tiling-tools
I now have a situation where I need to append the querystring to the re-written URL, for example:
http://www.site.com/section35/page1/tiling-tools/?myid=dskajh34kjhsvkjh34
need to become
http://www.site.com/search.asp?section=35&page=1&model=tiling-tools&myid=dskajh34kjhsvkjh34
My rules are:
RewriteEngine On
RewriteRule /\.htaccess$ - [F]
RewriteRule ^/section([^/]+)/page([^/]+)/?([^/]*)/?([^/]*)/?([^/]*)/$ /search_results.asp?section=$1&page=$2&model=$3 [L]
I've tried the following, without success:
RewriteRule ^/section([^/]+)/page([^/]+)/?([^/]*)/?([^/]*)/?([^/]*)/$ /search_results.asp?section=$1&page=$2&model=$3&%{QUERY_STRING} [L]
RewriteRule ^/section([^/]+)/page([^/]+)/?([^/]*)/?([^/]*)/?([^/]*)/$ /search_results.asp?section=$1&page=$2&model=$3 [L,QSA]
Suggestions will be appreciated ('cos it's driving me mad!)
Thank you!
Apart from the query string appending, I'm not even sure your rewrite rule is working at all?!? I would suggest to use something like this:
RewriteRule ^/section([0-9]+)/page([0-9]+)/(.*)/ /search_results.asp?section=$1&page=$2&model=$3 [NC,L,QSA]
The NC flag makes your rewrite rule non-case sensitive and the QSA flag adds the query string you need.

Resources