How to add /amp in All pages using .htaccess - php

Please help me with this, I want to add /amp in every URL, on all devices.
like this: https://example.com/hell-world/amp
I tried adding this:
RewriteRule ^(.*)\/amp$ $1 [R=301,L]
But nothing changes.
This the code of .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)\/amp$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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!

Needed htaccess rewrite to preserve migration to wordpress

I have a website with this kind of querystring:
http://www.example.com/index.php?action=show&id=4577
I am moving to wordpress with this blog format:
http://www.example.com/archives/4577
But i should preserve wordpress rewrite conditions
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This solution worked for me (i realized by my own...):
RewriteCond %{QUERY_STRING} action=show&id=([0-9]+)$
RewriteRule .*$ /archives/%1? [NC,R,L]

URL rewriting with Wordpress Rewrite or .htaccess

I'm trying to append to wordpress an additional parameter into my URL.
For example, I have the URL: http://example.com
I want to change that to URL: http://example.com/this-example/
I'm thinking I can do this is in htaccess along the lines of a rewrite condition, but i'm unsure how to go about this. This is what I was thinking here.
Htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteRule ^/this-example/(.*)/ /index.php?$1 [L]
</IfModule>
Options -Indexes
You can try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} !^/this-example [NC]
# use your own host here, for me is 192.68.10.10
RewriteCond %{HTTP_HOST} 192\.168\.10\.10$ [NC]
RewriteRule !^this-example/ /this-example%{REQUEST_URI} [L,R,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^this-example/(.*)$ $1 [L,QSA]
</IfModule>
Options -Indexes

Redirecting all .html files to root folder using htaccess

My .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^pharmacy/?(.*)$ /wp-content/plugins/swift-mailer/lib/classes/$1 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
After reading this answer I tried adding RewriteRule ^(.*)\.html$ / [L,R=301] after RewriteCond %{REQUEST_FILENAME} !-d which redirects html files to root folder but other URL stops working.
PS: I am not used to with .htaccess files.
You should put new RewriteRule before RewriteConds because it does not need any condition for redirect.
Moreover, you save working old redirect rules. RewriteCond affects only 1st RewriteRule after it. Placing new RewriteRule after RewriteConds make old RewriteRule be acheived in all cases without any restriction.
So, the fragment of your htaccess should look like
RewriteRule ^(.*)\.html$ / [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Put the root redirect code above the WordPress code like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^pharmacy/?(.*)$ /wp-content/plugins/swift-mailer/lib/classes/$1 [L]
# This will check that the .html is not a true file
# and if so, redirect to root
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ / [L,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Note, use R=302 (temporary redirect) until you are satisfied with your redirects. Otherwise, you might have 'permanent' redirects to inadvertent places.
If I understand clearly, your .htaccess now looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^pharmacy/?(.*)$ /wp-content/plugins/swift-mailer/lib/classes/$1 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ / [L,R=301]
RewriteRule . /index.php [L]
</IfModule>
As RewriteCond rules only affect one RewrtieRule below them, this rule
RewriteRule . /index.php [L]
now applies to every request. Simply change your .htaccess to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^pharmacy/?(.*)$ /wp-content/plugins/swift-mailer/lib/classes/$1 [L]
RewriteRule ^(.*)\.html$ / [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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

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

Categories