I have a WordPress theme with the following .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Which removes the "index.php" from the url. But I would like to remove some stuff from my start url, which looks something like "page.com/dir/dir2/page.html", to "page.com". So I tried adding
RewriteRule . /dir/dir2/page.html [L]
after the first rule, but it doesn't seem to work. What do I need to do to fix it?
RewriteRule ^dir/dir2/page\.html$ - [L]
This should work to.
Edit: little big mistake I did there. NOW it should work
Related
I know there are a lot of threads for .htaccess URL rewriting, but my case seems to be a bit different and I have tried a lot but it doesn't work.
My current URL: http://example.com/forest/trees/?type=perennial
What I need is: http://example.com/forest/trees/perennial
I just need to remove the ?type= from the URL.
EDIT: The URL may contain hyphens - between strings at any point (except the domain name ofcourse). It can be dense-forest or non-perennial too.
It's a custom code and plugin, so can't modify it. I just need the URL beautified.
Any help would be greatly appreciated.
What I've tried so far in .htaccess:
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /forest\/trees\/\?type=([^&]+)
RewriteRule ^ \/forest\/trees\/%2\/? [L,R=301]
and
RewriteRule ^\/forest\/trees\/([^/]*)? /forest/trees/?type=$1 [L]
My current Wordpress .htaccess is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks in advance. :)
Cheers!
You can use this .htaccess file:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^forest/trees/([^/]+)$ /forest/trees/?type=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Now URLs like http://example.com/forest/trees/perennial will internally redirect to /forest/trees/?type=perennial and then to Wordpress Dispatcher /index.php.
I'm using wordpress for a site,
this url before tes.com/index.php/about/
i want url like this tes.com/about/
I have tried copying parts of WordPress' .htaccess, however shows a 404 error.
My .htaccess file looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any ideas on where to start and how to accomplish what I'm looking for?
Go to your WP-ADMIN-->Settings-->Permalink and use the permalink structure change there, if it generate any .htaccess file copy the content and update your .htaccess file.
Or Check if your hosting mod_rewrite is enable by creating a file phpinfo.php with content,
Upload this file and browse via Browser. So you know which modules are enabled. You need mod_rewrite enable to remove index.php from URL.
Try this -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test.com/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test.com/index.php [L]
</IfModule>
The official instructions will give you clean urls. So best to follow this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Even after extensive research I was unable to resolve following redirection. I tried tons of examples, but with no luck.
From this URL:
http://www.example.com/store/product/name
I would like to get:
http://www.example.com/name
Problem is that the only known string is "store". Other strings "product" and "name" could contain letters, numbers and "-" or "_" characters.
I am testing it on live website and also on this tester: htaccess.madewithlove.be
One of the examples I used:
RewriteEngine On
RewriteBase /
RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]
This seems to work on above tester website, but not in real environment. I think there is something wrong with the regexp and second parameter is not properly returned or I am missing something else.
I should also mention that the website runs on Wordpress and in .htaccess file there is also following section created automatically by Wordpress:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks for your help!
Have your rule like this i.e. redirect before internal WP rule:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to ask is it correct the way that I add 410 to page in .htaccess in Wordpress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule http://exapmle.com/%D1%8BB%D1%83%D0%B3%D0%B8/ [G=410,L]
RewriteRule http://example.com/%D0%%D1%82%D0%B0%D0%BA%D1%82%D0%B8/ [G=410,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thank you!
you don't want the http://example.com part in the pattern, that's not part of the URI that's used for the pattern to match against
You don't need the =410 in the flags
The URI is already decoded by the time mod_rewrite rules get applied, so you don't want (I'm assuming) the URL encoded string.
Try:
RewriteRule ^ыBуги/ - [G,L]
RewriteRule ^ÐÑакÑи/ - [G,L]
If you want to show "Gone" error for those 2 URLs (mentioned in your code) then put this code right on top of .htaccess after RewriteBase line:
RewriteRule ^\xD1\x8BB\xD1\x83\xD0\xB3\xD0\xB8/?$ - [G,L]
RewriteRule ^\xD0\xD1\x82\xD0\xB0\xD0\xBA\xD1\x82\xD0\xB8/?$ - [G,L]
Do you mean:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/%D1%83%D1%81%D0%BB%D1%B3%D0%B8/ - [G,L]
RewriteRule ^/%D0%B7%D0%0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D0%B8/ - [G,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPdpress
or to put these two lines of URLs at the top ot the .htaccess file, outside of:
# BEGIN WordPress
I've written a Wordpress plugin that adds a query string to the URL. However I can't seem to modify the htaccess to rewrite this. Not sure if Wordpress is overriding it?
The current htaccess is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And the URL I'm trying to rewrite is:
http://domain.com/deal-info/?id=87&post_name=testdealtitle
Desired URL:
http://domain.com/deal-info/87/testdealtitle
I've tried adding:
RewriteRule ^([^/]*)/([^/]*)$ /deal-info/?id=$1&post_name=$2 [L]
to no avail. Any ideas appreciated!
When you do this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This means: "if it's not a file, and if it's not a dir, redirect all incoming URLs to
index.php.
Your rewriterule should work... unless you've put it after the previous rewriterule. So, in short, are you sure your .htaccess it like that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)/([^/]*)$ /deal-info/?id=$1&post_name=$2 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Please tell me if it works.
Moreover if you only want to redirect only deal-info, you should do something like (not tested):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(/)?deal-info/([^/]*)/([^/]*)$ /deal-info/?id=$2&post_name=$3 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Two hints:
Please try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)
May I ask you to add the rewritelog in your question?
After much confusion I found an answer here:
https://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule
Though I think the proper way to do it is by:
http://codex.wordpress.org/Rewrite_API/add_rewrite_rule
I'm not sure if you can do this directly in htaccess, or I was having a conflict problem with another plugin I was using.
Thanks again to Olivier for his extensive answer!