Need to rewrite URL in wordpress - 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>

Related

subdirectories blog post wordpress not shown in laravel

I'am using wordpress as my blog in my laravel site. The wordpress blog are placed in subdirectories so that the domain of the wordpress is mydomain.com/blog.
I've tested it in my localhost and it works perfectly. But when i deployed it on server the site can show the homepage of my blog. But it can't display the blog's page ex. domain.com/blog/contact (404 Page not found) .
I've done several steps like changed the .htaccess and define the WP_HOME /WP_SITEURL but it still doesn't works to show my blog post .
Here is my wordpress .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
And here are my laravel site's .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/blog/ # <=== NEW LINE!!!!
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
what am i doing wrong here?

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.

htaccess rewrite rules when using 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?

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 & .htaccess

I have a website under WordPress where I've created a new page www.foo.com/section/
The idea is to create a permalink like www.foo.com/param1/type/param2 and with .htaccess use a rewrite rule to: www.foo.com/section/?var1=param1&var2=param2&var3=type
RewriteEngine on
Options +FollowSymlinks
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2
I got it working in my old web but in the WordPress crashes.
#My rules -> copy&paste
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2
# 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've only got a beautiful WordPress' 404 page
I've read several questions here but no one helps me.
Thanks for your time and best regards,
R.
13 Jan
I've created a simple test to check it.
The new structure works with a test case without problems:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^lol/$ project/ [L] #Rule 1
RewriteRule ^foo/$ test/ [L] #Rule 2
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Rule 1, I've created a subfolder in WordPress root, named "project" with an index.php echoing "Hi dad" and when type www.foo.com/lol/ it loads that script and echoes the word.
Rule 2, I've created a new WordPress page, www.foo.com/test/
with a simple string to show, but when I write www.foo.com/foo/ it gives me error 404. It seems that the redirection to a wp pages doesn't works as I expected.
Disclaimer: Of course www.foo.com/test/
Now I'm stucked.
Thanks for your previous responses and future help.
Best regards,
R.
14 Jan
I have new news :)
The new .htaccess that works is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_\s-.()&]+)/alternator/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=A [L]
RewriteRule ^([a-z0-9_\s-.()&]+)/starter_motor/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=M [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Instead redirect to "elecfinder/" in the .htaccess I'm pointing to "?page_id=554", at least it doesn't gives me error 440
I'm working on an alternator and starter motors web.
I have a URL that is http://www.elecfinder.com/hitachi/starter_motor/s114850 that really is http://www.elecfinder.com/info/?supplier=hitachi&ref_num=M&reference=s114850, here I load the reference info.
http://wp.elecfinder.com/elecfinder/?reference=s114850&supplier=hitachi&ref_type=M is that web in wp, so my idea is to redirect http://wp.elecfinder.com/hitachi/starter_motor/s114850/ to this.
Now I'm able to redirect http://wp.elecfinder.com/hitachi/starter_motor/s114850 to http://wp.elecfinder.com/elecfinder/?page_id=554&supplier=hitachi&ref_num=M&reference=s114850 but there are 2 problems:
It changes the url to http://wp.elecfinder.com/elecfinder/ instead maintain wp.elecfinder.com/hitachi/starter_motor/s114850
Misses the GET parameters "reference","supplier" and "ref_type"
Thanks for your time.
Best regards,
R.
Try the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_\s-.()&]+)/(section1|section2)/([a-z0-9]+)$ section/?var1=$1&var2=$3&var3=$2 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Always put your rules after RewriteEngine on.
And, in this case (WordPress), be sure to put your rules before WordPress' rule (it is here to redirect everything to index.php because WordPress has a front controller and it manages rewriting itself).

Resources