I have this .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA]
I'd like to create an exception of the last rule: if the user enters example.com/somefoldername It should not redirect to index.php?p=somefoldername, but to ./somefoldername/index.php.
It is a very easy task I guess! But can't come up with a solution. I tried
RewriteCond ^somefoldername$ somefoldername/index.php but it didn't work.
Thanks in advance!
You can use:
RewriteEngine on
RewriteBase /
RewriteRule ^(somefoldername)/?$ $1/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
Related
I need some help with htaccess. Would you be so kind to assist a little bit?
I have a URL like this
https://example.com/index.php?p=application-intelligence
[or]
https://example.com/?p=application-intelligence
Basically the index.php is passed some parameter 'home' to know which page to load i.e. home.php
So I've tried to follow your post on your blog but with not much luck.
So I'd like the final code to be
https://example.com/application-intelligence
Here's my code.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1
Also for the
https://example.com?p=home
I'd like it to be just
https://example.com
You may use these rules:
RewriteEngine on
# handle /?p=home
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=home\s [NC]
RewriteRule ^ /? [R=301,L,NE]
# handle /?p=<something>
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]
This is what i have in my apache virtual host conf file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
i need a RewriteRule which changes an url of http://domain.org/foo/bar to http://domain.org/de/foo/bar but does nothing if there is an url like http://domain.org/en/foo/bar or http://domain.org/de/foo/bar
so if there is no en/ and no de/ then it should add de/, else it should do nothing
how can this be done? i already played around a bit with regex, but I dont know how to check if there is en/ or if there is no en/.
help is highly appreciated.
UPDATE:
my current rules are the default rules you should have when running wordpress:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
UPDATE2:
this is wordpress and de/ and en/ are not actual folders.. they are used by a multilanguage plugin. since i have some issues with this plugin i need the redirect as described above.
In general without any other rules, this would redirect anything that doesn't start with /en/foo/bar.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/en [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /de/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!(?:en|de)).*)$ de/$1 [L,NC,R]
Keep this rule before default WP rule.
EDIT Full .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!(?:en|de)).*)$ de/$1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have this url: http://example.org/product.php?course_id=$x
And I want this url changes to this: http://example.org/Course-Name
this is my code in .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ 404page.php
RewriteRule ^/([0-9]+)/([^/]+)/$ /product.php?course_id=$1 [L,R]
Which is not working kindly tell me whats wrong with my code?
You need to remove leading slash from your rule. Try this rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+product\.php\?course_id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /product.php?course_id=$1 [L,QSA]
i'm trying to solve a mod_rewrite rule for my webshop.
The URL is: localhost/myshop/category1/category2/myproduct.html
The rediret URLshould be: localhost/myshop/configurator/product/configure/id/1/s/myproduct/category1/5/
If I try a RewriteRule like this
RewriteRule ^myproduct\.html$ http://localhost/myshop/configurator/product/configure/id/1/s/myproduct/category1/5/
nothing happens and the redirect will not appear.
What i'm doing wrong?
my rewrite rules in .htaccess
RewriteBase /myshop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
RewriteRule ^myproduct\.html$ http://localhost/myshop/configurator/product/configure/id/1/s/myproduct/category1/5/
I want that myproduct.html redirects immediatly to the configurator link, so i want to implement a RewriteRule
Try re-ordering your rules:
RewriteEngine On
RewriteBase /myshop/
RewriteRule (^|/)myproduct\.html$ /myshop/configurator/product/configure/id/1/s/myproduct/category1/5/ [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ $1.php
RewriteRule ^(.*)\.html$ page.php?title=$1
I see that my rewriting rules are working but depends on the order of execution. If the pages rewrite rule is the first...it works only for the pages.php.
I've also "played" around with the flags but no results up there.
Try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)\.html$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)\.html$ page.php?title=$1 [L,QSA]