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]
Related
I'm trying to overwrite only the URLs that end in .html to have the extension removed and then add a trailing slash to the end.
This should result in something like foo.com/bar.html to foo.com/bar/ and still retrieve the html file in the root of the directories.
The below code is working but it can no longer find the .html file to load.
This is on WordPress and I'm thinking this is very important to understand to make this work correctly.
#test (does what it needs to but does not grab the file)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ $1_$2.html [L]
# end test
Don't worry! Simple copy and paste error on RewriteRule ^([^/]+)/?$ $1.php needs to be RewriteRule ^([^/]+)/?$ $1.html
#test (does what it needs to but does not grab the file)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.php # Obviously needs to be .html, not .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ $1_$2.html [L]
# end test
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]
I have a testing web where there is a testing directory lets say 'test' which contains wordpress directory lets say 'mywordpress', test and his content - excluding the mywordpress - is handled by its own .htaccess - I need the .htaccess to do nothing with the url that goes mydomain.com/test/mywordpressXX (XX can be "/" or "/anything...."
Ive tried something but this .htaccess still works with test content, but throws Internal 500 error when I am trying to reach WP admin:
RewriteEngine On
RewriteBase /test/
DirectorySlash On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ $1/ [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/mywordpress/?$
RewriteRule ^([^/?]+)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/mywordpress/?$
RewriteRule ^([^/?]*)/([^/?]*)$ $1.php?$1=$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/mywordpress/?$
RewriteRule ^([^/?]*)/([^/?]*)/([^/?]*)$ $1.php?$2=$3
What am I doing wrong? Or how is it done correctly ?
Thanks.
Try this .htaccess:
DirectorySlash On
RewriteEngine On
RewriteBase /test/
RewriteRule ^mywordpress(/|$) - [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ $1/ [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ $1.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]*)/?$ $1.php?$1=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]*)/?$ $1.php?$2=$3 [L,QSA]
Oh ! Silly me ! I forget about the RewriteBase /test/ you just have to make the exclude rule this way:
RewriteCond %{REQUEST_URI} !mywordpress/?$
There was an additional slash:
RewriteCond %{REQUEST_URI} !/mywordpress/?$
I want to install WordPress in subdirectory and remove index.php in permalinks.
The server is IIS 6.0, support rewrite.
My webserver has the following directories:
webroot
--wp [wordpress folder]
webroot/.htaccess
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
webroot/wp/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #3
It works when I visit a.luckyet.com and a.luckyet.com/hello-world.html
But it does not work when I visit a.luckyet.com/wp-login.php or a.luckyet.com/wp-admin
The #3 works fine, but #1 and #2 can not work properly. Then I saw here and change the content of webroot/wp/.htaccess to:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
It still does not take effect. Can anyone help me? Thanks in advance!
Update:
ISAPI_Rewrite version is 3.0.
All code in webroot/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
All code in webroot/wp/.htaccess:
RewriteEngine on
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule wp-(.*) wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule (.*) index.php/$1 [L]
Wordpress permalink is:
/%postname%.html
Thus, Wordpress can work fine when visit http://a.luckyet.com/ or http://a.luckyet.com/hello-world.html
Question:
If there is a real file like a.html in webroot/wp/, like webroot/wp/a.html, wordpress 404 error will be reported when visit http://a.luckyet.com/a.html, . How can I fixed this?
You're dynamically rewriting the URLs with the .htaccess file and WordPress settings to tack on the .html extension - any files that are "real-life" .html files are being handled upstream by the IIS Handler Mappings.
You'll have to update your Handler Mappings in IIS for .html files especially to direct the requests directly to the physical file.
I am using htaccess coppied from wordpress.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
It works fine.
I would like to add a script to redirect to sitemap.php file if user requests sitemap.xml.
I tried adding RewriteCond %{REQUEST_FILENAME} !-^sitemap.xml$ but didn't work.
Put the rule BEFORE that set of rules:
RewriteRule sitemap\.xml sitemap.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]