I need hide only one variable from get request my url:
http://example.com/profile/?id=5&username=demo
I trying to make:
http://example.com/player/demo
htaccess:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^player/([^/]*)$ /profile/?id=$1&username=$2 [QSA,B]
My solution here is to change
http://example.com/profile/?id=5&username=demo
to
http://example.com/player/5/demo
because if you use what you suggested
http://example.com/player/demo
there is an indication to username which is demo but there is no indication to id unless you do it like following :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^player/(.*)/(.*)$ /profile/?id=$1&username=$2 [QSA,L]
Related
Is it possible to using htaccess?
I want to keep my original url "menu", but also use /en/menu/ for it.
Here is my code so far (sorry I am terrible at htaccess):
RewriteEngine On
RewriteBase /server/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/menu/ [NC]
RewriteRule ^([^/]+)/([^/]+)en/menu/ [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /menu/ [L,QSA]
I'm trying to do some url like that: domain.com/category-subcategory.
If I go to domain.com/category Its work, but if I trying to go to domain.com/category-subcategory it is not working..
this is my code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ category.php?category=$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)/$ category.php?category=$1&subcategory=$2 [L,NC]
How can I fix it? Thanks
Edit: I fixed it! here is the code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)$ category.php?category=$1&subcategory=$2 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ category.php?category=$1 [L,NC]
I was only need to remove the slash before the $ at the end. Thanks for everyone!
Try with below,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)$ category.php?category=$1&subcategory=$2 [L,NC]
Here is the code I use to get three virtual subfolders with .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?url=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?url=$1&sub=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?url=$1&sub=$2&subsub=$3 [L]
the question is: is it possible to make it simpler? For example:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?url=$1&sub=$2&subsub=$3 [L]
I know this won't work. I am just trying to figure out if it is the only way to add more subfolders. What if I need, let's say, six (url/sub/sub2/sub3/sub4/sub5....etc)??
Thank you in advance
I have to rewrite some url on my site. I've put this in my htaccess to make this change:
http://example.com/john/?a=1&b=2 --> http://example.com/index.php?account=john&a=1&b=2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ ./index.php?account=$1 [NC,QSA,L]
Now I have to rewrite images url in this way. Every image with this path: example.com/john/images/a.jpg
Should point to phisical path: example.com/accounts/john/images/a.jpg
How can I do that?
Note: "John" is not fixed but can be every possible word.
You can try this script:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?account=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/images/([^/]+).jpg$ /accounts/$1/images/$2.jpg [NC,L]
I can't fix this issue. I'm trying to get rewrite rules to work with dynamic urls like:
http://example.com/[CATEGORY]/[PAGE]/[OPTIONS]
or
http://example.com/[PAGE]
This is my .htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^(.*[^/])
RewriteRule ^(.*[^/]) /index.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^(.*[^/])\/^(.*[^/])
RewriteRule ^(.*[^/])\/^(.*[^/]) /index.php?url=$1/$2 [QSA,L]
The first rewriterule is working, but the second isn't. Also is this not clean.
Anyone who knows this?