What is this .htaccess file doing??? I don't know anything about .htaccess .please help.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
RewriteEngine On
This turns on the rewrite engine, all the rules get ignored if this isn't in the htaccess file
RewriteBase /
This tells the rewrite engine that relative URL-paths should use this as its base
RewriteRule ^index\.php$ - [L]
This rule means: "If the request is index.php, then pass it through the rewrite engine and stop rewriting"
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
This rule matches against <some stuff> then wp-admin, and redirects the browser to the same URL except it ends with a slash. Example: http://example.com/foo/bar/wp-admin gets redirected to http://example.com/foo/bar/wp-admin/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
This rule says if the request is for a file or directory that exists, pass it through the rewrite engine and stop rewriting.
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
This rule matches against <some stuff> then wp-content or wp-admin or wp-includes, and rewrites the URI to everything after the <some stuff> Example: http://example.com/blah/blah/wp-admin/some/more gets rewritten to /wp-admin/some/more.
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
This rule matches against <some stuff> followed by any php file, and rewrites the URI to everything after the <some stuff>. Example: http://example.com/abc/123/somefile.php gets rewritten to /somefile.php.
RewriteRule . index.php [L]
Finally, if none of the other rules got applied, this rule rewrite everything else to /index.php.
Related
Please help, I have already been doing for 2 days and all in vain...
This code works well for rewriting directories and pages to one index.php page
DirectoryIndex /index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.php [NC,L]
RewriteRule ^/sitemap.xml sitemap.php [L]
The problem with sitemap.xml as it has to be rewritten into sitemap.php rather than into index.php
You would need to put the sitemap rule before the index rule. Rules are processed from top to bottom and once it hits the index rule (because .* would match sitemap.xml), it would stop processing further because of the [L] flag.
Another option would be to just use php and inside index.php, include sitemap.php; when $_SERVER['REQUEST_URI'] equals sitemap.xml. Same result.
Okay, I used an automated generator to generate a custom URL for my prestashop site in the .htaccess file, but it does not work. Any ideas?
the original URL is:
http://www.example.com/de/suche?controller=search&orderby=position&orderway=desc&search_query=mutter&submit_search=OK
the rewritten url should be:
http://www.example.com/search/position/desc/mutter/OK.html
and the rewrite rule I have in the .htaccess file is:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /de/suche?controller=$1&orderby=$2&orderway=$3&search_query=$4&submit_search=$5 [L]
You should remove the [L] flag from your rule. It prevents any other rule to apply but you need to passe this new route to Prestashop dispatcher.
<IfModule mod_rewrite.c>
RewriteEngine on
#Domain: test.example.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
# [...]
# You need to put your condition here without the [L] flag
# And before the Dispatcher
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /de/suche?controller=$1&orderby=$2&orderway=$3&search_query=$4&submit_search=$5
# Your URL is then rewritten to Prestashop standard format
# and will be sent to the following Dispatcher.
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
I am having some issues with Apache rewriting rules.
On my webserver the following files with a leading "s" exist (exerpt):
search.php
stats.php
status.php
Now, i want to rewrite search.php to simply s.
But when i now call status.php, my search.php is being included.
RewriteEngine on
RewriteRule ^stats$ stats.php
RewriteRule ^status$ status.php
RewriteRule ^s search.php # <---
RewriteRule ^live$ live.php
RewriteRule ^about$ about.php
RewriteRule ^i$ item.php
RewriteRule ^compare$ compare.php
DirectoryIndex home.php
How can i force Apache to only rewrite search.php to s if the URL is like
http://localhost/s/PARAM1/...
I tryed RewriteRule ^s/ search.php without success.
EDIT: 404 Error at .../s/PARAM1/..., stats, etc. works.
I hope you'll understand my issue although I'm not very familiar with the rewriting rules.
Reorder your rules and make use of regex to reduce your rules like this:
DirectoryIndex home.php
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(statu?s|live|about|compare)$ $1.php [L,NC]
RewriteRule ^i$ item.php [L,NC]
RewriteRule ^s/ search.php [L,NC]
I'm wanna rewrite all incoming URLs who at end have %3Ffull%3D1 to ?full=1
I'm try this in htaccess but not work:
RewriteRule ^(.*)%3F(.+)%3D(.+)$ $1?$2=$3 [R=301]
here is full .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)%3F(.+)%3D(.+)$ $1?$2=$3 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I recently implemented the following .htaccess code to accomplish this - I've modified it to fit your scenario of using the "full" parameter.
# replace %3F with ? and %3D with =
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\%]+)\%3[Ff]full\%3[dD]([^\ ]+)\ HTTP/
RewriteRule \.*$ http://www.mywebsite.com/%1?full=%2 [R=301,L]
Try adding the L flag in the rule that handles the query string:
RewriteRule ^(.*)%3F(.+)%3D(.+)$ $1?$2=$3 [L,R=301]
otherwise, the rewritten URI could end up getting handled by the last rule (RewriteRule . /index.php [L]) and yet still get redirected because the URI was flagged for a 301. Also, if the original URL that you are trying to redirect contains %3Ffull%3D1 in the query string itself, then your rule isn't going to match that, you'd need something like:
RewriteCond %{QUERY_STRING} ^(.*)%3Ffull%3D1(.*)$
RewriteRule ^(.*)$ $1?%1&full=%2 [L,R=301]
i have to call my pages in this way:
http://example.com/index.php?page=homepage
i want to always show the url in this way
http://example.com/homepage
and at the same time i also want to prevent the insertion of the / at the end of the url...so:
http://example.com/homepage/ or http://example.com/homepage
point to the same page.
how can i do this trick with htacces? have i to correct all relative path of files in my html?
thanks a lot
# activate Rewrite Engine
RewriteEngine On
# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# remove trailing slash
RewriteRule ^(.+)/$ $1 [R=301,L,QSA]
# rewrite all other requests to index.php
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
RewriteEngine on
RewriteBase /
RewriteRule ^(css|js)/(.*)?$ $1/$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
RewriteRule ^(.*)/$ $1 [R]
Last update from this.