I'm trying to add a custom rewrite rule for my WP site so http://example.com/?u=sample-output, is rewritten as http://example.com/sample-output.
The rewrite rule I'm trying to add is:
RewriteEngine On
RewriteRule ^([^/]*)$ /?u=$1 [L]
The existing rewrite rule is:
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
When I add it in, it gives me a 404 error when I visit the page. I'm guessing this is because of a conflict. Any suggestions on how to fix this would be greatly appreciated.
Based on your comments, put the rule above the WP rules and then you can do something like this. And all URLs that will go to the query string would have to use /start/ in it. Then make sure to ignore /start/ in the WP rules like below for all others.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^start/([^/]+)/?$ /?u=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/start [NC]
RewriteRule . /index.php [L]
Related
I have following rewrite rule in htaccess and its not working for first part for EventList.php. Will appreciate some help to figure out whats wrong. I am adding this in a wordpress website htaccess file.
RewriteEngine On
RewriteRule ^Local-Event/([0-9]*)$ /Eventbrite.php?page=$1 [QSA]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I want my wordpress site redirections to remember the url but place it in a subfolder.
So http://www.example.com/test123 has to redirect to http://www.example.com/voetbal/test123
And http://www.example.com/0239 to http://www.example.com/voetbal/0239
My htaccess looks like this.
RewriteEngine On
RewriteBase /voetbal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /voetbal/index.php [R=301, L]
this makes my site go from http://www.example.com to http://www.example.com/voetbal/
but only the root.
How can i make my htaccess to remember peoples input and place it after the /voetbal/
Try :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /voetbal%{REQUEST_URI} [L,R=301]
I would appreciate some help to make this Wordpress RewriteRule to work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mywebsite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mywebsite/index.php
RewriteRule ^/news-mywebsite/([a-z]+)$ /news-mywebsite/?cat=$1
</IfModule>
The url I want to rewrite is this
http://localhost/mywebsite/news-mywebsite/?cat=news
I'd like to rewrite it as
http://localhost/mywebsite/news-mywebsite/news
I tried to search also on google but I can't understand the reason why it is not working htaccess.
Do you check this rule on the the page like this http://htaccess.mwl.be/ ?
Remove slash / . In .htacces a path is without slash.
You need to Reorder your rules and remove the leading slash from RewriteRule's pattern :
RewriteRule ^news-mywebsite/([a-z]+)$ /news-mywebsite/?cat=$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mywebsite/index.php [L]
Here is the problem I've stalled for days.
My setup is Wordpress with Woocommerce installed. Permalinks structure works great, so I just need to redirect old URLs to the new ones.
Old url structure looks like this:
http://domain.tld/?product=bla-bla
But I need them to redirect like this:
http://domain.tld/product/bla-bla
*bla-bla is dynamic part.
The rule in .htaccess I've made:
RewriteCond %{QUERY_STRING} ^product=(.*)$ [NC]
RewriteRule ^$ /product/%1 [NC,L,R=301]
But the result is partially wrong:
http://domain.tld/product/bla-bla?product=bla-bla
The contents of the .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} ^product=(.*)$ [NC]
RewriteRule ^$ /product/%1 [NC,L,R=301]
I would appreciate any help!
Have it this way:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^product=(.*)$ [NC]
RewriteRule ^$ /product/%1? [NC,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
? at the end of target will strip off any query string from original URL.
I would like to fake or even hide my wordpress directory from
mysite.com/wp-content/themes/twentyfourteen/page.php to mysite.com/directory/page.php
or even mysite.com/wp-content/themes/twentyfourteen/page.php to mysite.com/fake1/fake2/fake3/page.php
Within my .htaccess file im using the following commands:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wp-content/themes/twentyfourteen/([^/]+)$ /fakedirectory$1 [L]
I;ve also tried
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wp-content/themes/twentyfourteen/([^/]+)$ /fakedir1/fakedir2/fakedir3$1 [L]
But for some reason this is not working... Any help would be appreciated!! Thanks
You're doing the opposite.
Try this way (assuming your htaccess is in root folder)
RewriteCond %{THE_REQUEST} \s/wp-content/themes/twentyfourteen/([^\s]*) [NC]
RewriteRule . /fakedirectory/%1? [R=301,L]
RewriteRule ^fakedirectory/(.*)$ /wp-content/themes/twentyfourteen/$1 [L]