htaccess rewrite rules when using Wordpress - wordpress

I have a site running on Wordpress. I also have a couple of custom pages running in subfolders. My issue is that my existing rewrite rules no longer work when using permalinks in Wordpress. I have the following in my htaccess:
RewriteEngine On
#Wordpress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#Custom
RewriteRule ^e/booking/(.*)/(.*)/$ /events/booking.php?event_id=$1&hotel=$2
RewriteRule ^e/(.*)$ index.php?url_friendly_name=$1
it may be an obvious question, but I don't know how to make my custom rewrites work with wordpress?

Related

Need to rewrite URL in wordpress

I am using wordpress in a subfolder of main domain
Ex. domain.tld/sub
I have a blog(post) in this wordpress installation
That is domain.tld/sub/blog will give me listing page
and domain.tld/sub/blog/this-is-a-blog will give me a blog detail page
I am using POST for showing this. Now i need to rewrite the URL so that from
Current URL Structure
domain.tld/sub/blog will become
domain.tld/blog
and all individual blog post should become
domain.tld/sub/blog/this-is-a-blog
TO
domain.tld/blog/this-is-a-blog
I tried below code but not working
RewriteEngine On
RewriteRule ^blog/(.+)$ sub/blog/$1 [L]
My HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /bim/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.+)$ bim/blog/$1 [L]
RewriteRule . /bim/index.php [L]
</IfModule>

WordPress admin pages redirecting to homepage

i have an issue with WordPress. The site working pretty normal but on the admin panel, various pages like edit post, installed plugins, add new plugin, add new page, settings redirects me to homepage. I'm googling like crazy for 3 days but i just found the mod_security issue. And it turned out useless for me too.
here is my .htaccess file
RewriteEngine On
RewriteBase /
RewriteCond /home/gokkur/public_html/wp-content/sitemaps%{REQUEST_URI} -f
RewriteRule \.xml(\.gz)?$ /wp-content/sitemaps%{REQUEST_URI} [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
SecFilterEngine Off
SecFilterScanPOST Off
this is default content of WP .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
Maybe your custom rewrite rules generating problems.

Wordpress returns 404 on existing file

I have the following stucture:
Wordpress installed in root, and an /api/api.php file manually created
When I go to www.example.com/api/api.php I get a 404
This is my .htaccess in the root folder:
Options +FollowSymLinks
RewriteRule ^api/api\.php$ - [L]
# 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
I expect this should have let requests to /api/api.php through unmolested.
Also, I tried putting in a .htaccess file in /api with just
# disable the rewrite engine
RewriteEngine off
but I am still getting a 404 error despite this.
The rest of the site works fine, and I have tried disabling all WP plugins just in case.
try change your permalink from admin panel or if you have an IIS7 server then your permalink should be like %postname%index.php.
and also try this .htaccess code and instead of 'example' write your site base path name
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /example/index.php [L]

Wordpress messed up our htaccess redirect, how to modify to work with Wordpress' htaccess code?

We had several domains parked on top of our main website. This was a normal HTML website and we used the following redirect so that the domain would 301 redirect to the proper url to avoid getting dinged by Google.
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
So the above htaccess code just rewrites the url to www.ourmainsiteurl.com, which is what we want.
Now here's the problem... we installed Wordpress and it has the following default htaccess code:
# 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
I tried to add my redirect code in but that broke Wordpress. Can anyone tell me what I need to use to make this work?
Simply put I want all the parked domains (ie: parkedurl1.com, parkedurl2.com, etc) to be redirected to www.ourmainsiteurl.com with the htaccess file.
Make sure the redirect is before any wordpress rules:
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$ [NC]
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
# 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
If it's still not working, check to see if wordpress has something turned on that is redirecting, or adding/removing the "www" from the hostname.

wordpress redirect loop on mod rewrite

I have wordpress setup to change the admin url to www.mydomain.com/admin. But now I have updated the permalinks to use the post name instaed of the id I get a redirect loop when I try to access the admin page. The problem is with the extra rules wordpress asked me to add to the .htaccess but I am unsure how to change it to allow both rules.
Wordpress 3.5.2 rewrite rules as below.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteRule ^admin/(.*) wp-admin/$1?%{QUERY_STRING} [L]
Anyone know what i need to do to allow both rules?
Was trying out a few solutions and it would seem that having the rewrite rule for changing the admin url to www.mydomain.com/admin BEFORE the mod-rewrite rules is the key to allowing both rules to work together. See updated/fixed .htaccess code below.
RewriteRule ^admin/(.*) wp-admin/$1?%{QUERY_STRING} [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Resources