I'm looking for the right .htaccess rule to make a Facebook.com/user URL like
What I want if I access for example
www.domain.com/StackOverFlow
It will be rewrite to
www.domain.com/index.php?category=StackOverFlow
Or
www.domain.com/category.php?item=StackOverFlow
Any help? I've tried some question here, but they doesn't explicit do this behavior.
Thanks in advance
Edited:
Forgot to say that I only want to be redirected using this rule, anything that after the domain, doesn't have any extension
For example it should redirect www.domain.com/categoryDescription but no www.domain.com/categoryDescription.php or www.domain.com/categoryDescription.html
The example below takes the URI after .com/ and assigns that to $1.
You can do the same for "item"
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?category=$1 [L]
<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite URLs of the form 'x' to the form 'index.php?category=x'.
RewriteRule ^(.*)$ index.php?category=$1 [L,QSA]
</IfModule>
Try:
RewriteRule ^StackOverFlow$ index.php?category=StackOverFlow [NC,L]
or:
RewriteRule ^StackOverFlow$ category.php?item=StackOverFlow [NC,L]
In generally:
RewriteRule ^([^/]*)$ index.php?category=$1 [NC,L]
or:
RewriteRule ^([^/]*)$ category.php?item=$1 [NC,L]
Related
I want to create pretty url. But, I got some problem with .htaccess. For example I have url domain/some.php?f=query-string.
I want to change domain/query-string (expected url). Is that possible to change / redirect via .htaccess. Or maybe from php file itsself.
this is a bit of htaccess snippet i made, but i get it blank/error page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
</IfModule>
Thanks for your attention.
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
In .htaccess, the URL-path matched by the RewriteRule pattern does not start with a slash, so the above will never match and it will do nothing. This should be written like the following instead:
RewriteRule ^([^/.]+)$ some.php?f=$1 [L]
The NC flag is not required here, since the regex is already "case-insensitive".
I am trying to set up my api to have 2 endpoints, and the simplest way I have seen to do this is to have a .htaccess file that would redirect something like www.website.com/api/category/platform to display the same as www.website.com/api/index.php?category=platform . The issue I am now running into is that I want it to include a second parameter such as www.website.com/api/index.php?category=platform&filter=price to be the same as www.website.com/api/category/platform/price or even www.website.com/api/platform/price
The current .htaccess file is
RewriteEngine On
RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]
I figured it out and I was able to use something along the lines of
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ project3/api/index.php?category=$1&filter=$2 [L]
You can use smthing like this.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?category$ $1category/ [R=301,L]
RewriteRule ^ - [L]
RewriteRule . index.php [L]
i get the $_GET['id'] from url to show a page, to htaccess i have the follow code to show like this shop/123 and not shop.php?id=123
RewriteEngine on
RewriteRule shop/(.*)/ shop.php?id=$1
RewriteRule shop/(.*) shop.php?id=$1
My problem is .. If i add to url shop/123/test/test/test this still working again and i have problems with the share links etc.
How i can fix it to takes only one parametes else to go to 404?
Sorry for my English
You can use this :
RewriteEngine on
RewriteRule ^shop/([^/]+)$ /shop.php?id=$1 [L]
This will rewrite /shop/foobar to /shop.php?id=foobar, but will not rewrite /shop/foobar/ with a traling slash or extra path-info .
If id is only numerical, you can change the rewrite rule to this:
RewriteEngine on
RewriteRule shop/(\d+)/ shop.php?id=$1
RewriteRule shop/(\d+) shop.php?id=$1
If you also have alphabets in id:
RewriteEngine on
RewriteRule shop/([a-zA-Z\d]+)/ shop.php?id=$1
RewriteRule shop/([a-zA-Z\d]+) shop.php?id=$1
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
RewriteRule ^shop/([0-9]+)/(.*) shop.php?id=$1 [L]
RewriteRule ^shop/([0-9]+)/(.*)/ shop.php?id=$1 [L]
Hope this will work. Thanks.
I have a website that on one specific page it requires an extra variable.
At the moment, the htaccess I am using is:
RewriteEngine On
RewriteRule ^([^/]*)/$ /index.php?page=$1 [L]
Which works fine with one variable.
How would I get it to work with :
http://tessite.com/index.php?page=test&id=1
So it looked like:
http://tessite.com/test/1
Thanks for any help or replies.
It can be coded like this:
RewriteRule ^([^/]*)/([^/]*)/$ index.php?page=$1&id=$2 [L]
RewriteEngine On
RewriteRule ^(.*)/(.*)/$ /index.php?page=$1&id=$2 [L]
RewriteRule ^(.*)/$ /index.php?page=$1 [L]
Just add $2!
Also, [^/] isn't required, you can simply use ..
I need a rewrite rule to rewrite the following:
www.abc.com/page/xyz to www.abc.com/xyz
remove **"page"** from url
I think it's more like this:
RewriteBase /
RewriteRule ^(.*)$ page/$1 [L]
If I understand what you're trying to do.
Like so:
RewriteBase /
RewriteRule ^page(/.*)?$ $1 [L]
If you only want to redirect page/xyz then you can use:
RewriteEngine on
RewriteRule ^/page/xyz$ /xyz [L]
If you want to redirect anything within the page directory, then use:
RewriteEngine on
RewriteRule ^/page(/.*$)$ $1 [L]