Getting value with symbol from htaccess - .htaccess

This url
example.com/ad/load.php?id=pay.jpg
would become
example.com/ad/pay.jpg
I tried to do this.. but it doesn't work.
Here is my htaccess (into ad folder)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /ad/
RewriteRule ^(\w+) ./load.php?id=$1
Edit
on this root example.com/ad/ I want to show index.php but it does not show. how to fix it

You regex should allow dot also. Try this in /ad/.htaccess:
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /ad/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w.-]+)/?$ load.php?id=$1 [L,QSA]

Related

.htaccess URL rewriting does not work

I wrote this code into my .htaccess file, but it seems not to work.
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^([^/]*)\.html$ /category/test.php?name=$1 [L]
When writing http://example.com/z.html it automatically redirects me to 404 file.
Do you have any suggestions?
Make sure you have mod_rewrite enabled and try your rules this way.
Options -MultiViews +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.html$ /category/test.php?name=$1 [L]

Exclude folders when redirect with htaccess

I have a question.
I want to redirect domain.com/var to domain.com/id=var
I can do that, but when users write a var like my folders, the htaccess redirect to the folder first :/
This is my actual htaccess
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-+/]+)$ index.php?id=$1 [L]
RewriteRule ^([a-zA-Z0-9-+/]+)/$ index.php?id=$1 [L]
But when the user write for example css, the htacces redirecto to domain.com/css/?id=css
And the second problem is if the user put / after the var, example domain.com/var/
How can I change that? Thx 4 all!!
You need to skip files/directories from rewriting:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9+/-]+)/?$ index.php?id=$1 [L,QSA]

htaccess RewriteCond for subdirectory not working

I have my .htaccess file written as such for my main program in the top directory but also want to exclude a sub-folder where I want to run another program.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond {REQUEST_URI} !=/ecart
RewriteRule ^files/ - [L]
RewriteRule ^(.*)/$ index.php?layers=$1 [L]
</IfModule>
I am trying the RewriteCond but it's not working.
It should go to the ecart/index.php file but still I am being brought to the front domain when I put my address in as www.mydomain.com/ecart
Your code has syntax error with logical errors. {REQUEST_URI} has missing % sign and RewriteCond is applicable to next RewriteRule only. Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/ecart(/.*|)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ /index.php?layers=$1 [L,QSA]

.htaccess remove index.php and hide parameter name

I have the following URL
www.site.com/index.php?key=blah
I want to make it like the following using .htaccess
www.site.com/blah
How can i achieve this using .htaccess?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /index.php?key=$1 [L,QSA]
it is what i'm using on my website, it works on local too.
Options -Indexes
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?key=$1 [L]
</IfModule>

htaccess url shortening works locally not on server

I wonder if anyone can take a look at this htaccess and tell me why it should work on a localhost but not on server
Options +FollowSymlinks
RewriteEngine On
RewriteBase /subdirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news(.*)$ news.php?q=$1 [L,QSA]
RewriteRule ^view/([^/]+)/([^/]+).html /view.php?content_id=$1&content_id=$2 [NC]
Try to remove RewriteBase /subdirectory or rename it to RewriteBase /.

Resources