404 error not work for /%post_id%/%postname%.html - php

i use /%post_id%/%postname%.html in my wordpress permalink.
404 eror dont work for this permalink if post or page not exist.
but for another link 404 work good.
this is my htaccess file :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
thanks for your help.

Check this might be help you
set apache to "AllowOverride All"
mod_rewrite is present, .htaccess looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wikiarr_prd/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wikiarr_prd/index.php [L]
</IfModule>
# END WordPress
Permalinks structure:
/%postname%_%post_id%.html

Related

SEO friendly URL parameters via .htaccess

I want to rewrite the URLs from:
https://www.example.com/bibliorafturi/?wpsolr_fq%5B0%5D=pa_culoare_str%3AAlbastru
to this:
https://www.example.com/bibliorafturi/Albastru
Another example:
https://www.example.com/bibliorafturi/?wpsolr_fq%5B0%5D=pa_culoare_str%3AAlbastru&wpsolr_fq%5B1%5D=pa_brand_str%3AESSELTE
to this
https://www.example.com/bibliorafturi/Albastru/?wpsolr_fq%5B1%5D=pa_brand_str%3AESSELTE
So I need only pa_culoare_str to be SEO friendly.
How can I do this with .htaccess?
UPDATE:
This is my .htaccess file now:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} /(.*)/(.*)/(.*)/?$
RewriteRule ^ /%1?wpsolr_fq[%3]=pa_culoare_str:%2 [QSA,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thank you!

Htaccess Directive to Show Content of Other Page Pattern URLS

I have the following page patterns:
mydomain.com/?myquery=34
mydomain.com/?myquery=38
mydomain.com/?myquery=42
Which I would like to access the content via:
mydomain.com/myquery/34
mydomain.com/myquery/38
mydomain.com/myquery/42
So when a user gets for example mydomain.com/myquery/34 (this page does not exist), he sees the content of mydomain.com/?myquery=34 (this page exists).
I am using the following htaccess rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteRule ^/myquery/dir1$ /?myquery=dir1 [L]
But the rule does not appear to work. Can you please help?
Can you try this below rules,
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/myquery/(.*)$ index.php?myquery=$1 [L,QSA]

404 error on all pages after changing directory

I changed the folder location of my site from www.example.com to www.example.com/users/ now but now all the links show 404 error when clicked on.
my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
application folder htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
the RewriteBase should be /users/
RewriteRule ./users/index.php

Slim Framework proper htaccess setup with wordpress

I want to make an api with slim. it would be on my "tools" subdomain in a directory called api.
http://tools.fifaguide.com/api
What should my .htaccess file look like?
Currently my .htaccess is located in my Wordpress directory (html -> .htaccess), and it looks like this:
<IfModule mod_rewrite.c>
//my part
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/index.php
RewriteRule ^api/(.*) http://tools.fifaguide.com/api/index.php [L]
//wordpress part
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The problem with this is that when I try
http://tools.fifaguide.com/api/hello/steve
I imediately get redirected back to api/index.php instead of staying on /api/hello/steve and having the results shown.
Its seems like wordpress is making this happen, but how do I prevent it?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ api/index.php [QSA,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

htaccess help in coexisting Codeigniter and Wordpress install

My intention here is to have a codeigniter app with a blog under the same domain. The admin for both should be separate.
The directory structure is this:
httpdocs/.htaccess
httpdocs/application/ <== CI installation
httpdocs/blog/ <== WP installation
httpdocs/blog/.htaccess
URLs would be like this:
mysite.com <== CI
mysite.com/tools <== CI
mysite.com/forum <== CI
mysite.com/blog <== WP
I followed this tutorial to set up and it worked nicely.
Both my codeigniter app and WP blog home page show exactly as they should, with correct URLs, styles etc.
I can also access mysite.com/blog/wp-admin normally for WP back end stuff.
My issue is when I try to access an actual blog post, for example:
mysite.com/blog/fiction/what-is-going-on/
When I do this, I get Codeigniter's 404 error page.
My root .htaccess (httpdocs/.htaccess) is this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|blog|assets)
RewriteRule ^(.*)$ index.php/$1 [L]
My blog .htaccess (httpdocs/blog/.htaccess) is this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any idea what I'm doing wrong? Will post more info if requested. Thanks in advance.
OK the solution is to use
CI .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
and
WP .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
That did the trick. Now all pages show without a problem.
I generally use 2 sets of conditions on the CI .htaccess (one on the root folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ blog/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This will allow the processing of blog URLs first and then deal with the CI URLs. You need to be careful not to have any controllers or routes using the term blog in your application.
I would try three things in your Wordpress .htaccess (don't touch the CI one -- it looks correct):
First, try removing the forward slash from before your index.php:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
If that doesn't work, then instead, try setting the RewriteBase to /blog/:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Finally, if neither of those things work, you can try manually adding "/blog/" to your index.php line at the end:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

Categories