Using .Htaccess url redirection - .htaccess

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]

Related

How to add a rewrite rule to remove paramaters in htaccess? [duplicate]

I Want to rewrite the url using .htaccess
Plz Read the code, and you well Get to know What I mean
My URL :
article.php?id=1&title=example
Using this in .htaccess
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+)$
article.php?id=$1&title=$2 [NC,L]
I get
article/1/example
What i need is
article/example
So something like this:
RewriteRule ^article/([0-9a-zA-Z_-]+)$ article.php?title=$1 [NC,L]

How do i URL rewrite using .htacess

i need some help rewriting URL using .htaccess my urls looks like:
http://www.example.com/testro2/product.php?id=426834&productStore=396
And i need have it work with text into it, example:
http://www.example.com/testro2/product/{anythinghere}/id=4268334&productStore=369
or you can make it look more clear like removing id= and &productStore= will be great, else i can use with them. example
http://www.example.com/testro2/product/{anythinghere}/4268334/396
The thing is that i need to have my keyword anythinghere in the URL.
Also, i would like to rewrite
http://www.example.com/testro2/search.php?q=shoes
TO
http://www.example.com/testro2/search/shoes
You can put this code in your /testro2/.htaccess
RewriteEngine On
RewriteBase /testro2/
RewriteRule ^product/.+/(\d+)/(\d+)$ product.php?id=$1&productStore=$2 [L]
RewriteRule ^search/(.+)$ search.php?q=$1 [L]

how to attach multiple parameter to index.php using rewrite rule?

hi i am trying to make clean and neat url using rewrite rule
I want to achive :
abc.com/t/param1/param2
Rewite rule that I wrote
RewriteRule ^t/(.+)/(.+)$ t/index.php?v=$1&t=$2 [L]
but it doen't work it redirects to :
http://abc.com/?v=param1&t=param2
Your regex should only match characters that aren't slashes. So your rule should look like
RewriteRule ^t/[^/]+/[^/]+$ t/index.php?v=$1&t=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/$ /?v=$1&t=$2 [L]

URL Rewrite using htaccess for one variable

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.

SEO Friendly URL Command in .htaccess

I have a dynamic page that looks like the following:
www.sitedomain.com/page.php?id=30&name=about_our_company
I want to make my website links SEO friendly by having something like the following:
www.sitedomain.com/about_our_company.html
Or
www.sitedomain.com/about_our_company
My question is: what regex/code I should have in the .htaccess file?
Thanks
This ofc has a fixed id of 30.
RewriteRule ^about_our_company/?$ /page.php?name=$1&id=30 [NC,L]
since /about_our_company doesn't include the ID, it's impossible to invent the ID correctly.
the way I do it in my own CMS is to have something like this in the .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ /index.php?page=$1 [QSA,L]
then in index.php, use the $_REQUEST['page'] (assuming PHP) variable to find the right page details in the database
You could improve this to be more generic:
RewriteRule ^([^/]+)/([^/]+)?$ /page.php?id=$1&name=$2 [NC,L]
The following URL's would all match:
http://example.com/30/about_our_company
http://example.com/29/contact
http://example.com/10/our_work

Resources