I'm trying to remove the trailing slash from our URLs. I adjusted our .htaccess file and added this code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
Unfortunately this didn't work as the pages (except for the homepage) suddenly show too many redirects and I get a message from the system saying "The page isn’t redirecting properly".
I was thinking maybe I made an error in the way I inserted the code. Originally, our .htaccess file has this:
# 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
# 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
After adjusting it to insert the code, it looked like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And that resulted in an error. Can anybody point out where I went wrong? Thanks.
Turns out it's a Wordpress issue. It's something you can adjust by going to your Wordpress site's Permalink Settings. From here you can choose your preferred URL format. "With-trailing-slash" is the default format so you definitely need to make an adjustment if you want the typical "without-trailing-slash" format.
Related
I am trying to use pretty urls so https://example.com/event/1/dog-singing will load https://example.com/events?action=show&id=1
I added the following code to my .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^event/([^/]*)/?(.*)$ events?action=show&id=$1 [L,NC]
I get a 404 page.
I tried using
RewriteRule ^event/([^/]*)/?(.*)$ index\.php/events?action=show&id=$1 [L,NC]
Same 404 page.
The below rewrite works. But I don't want to load the script from the subdirectory.
RewriteRule ^event/([^/]*)/?(.*)$ wp-content/plugins/testplugin/testplugin\.php?action=show&id=$1 [L,NC]
The one below also works. But it changes the pretty url in the address bar.
RewriteRule ^event/([^/]*)/?(.*)$ https://example.com/events?action=show&id=$1 [L,NC]
EDIT
Here is the full .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^event/([^/]*)/[^/]*/?$ index.php?action=show&id=$1 [QSA,L,NC]
RewriteRule ^register/([^/]*)/?(.*)$ wp-content/plugins/testplugin/testplugin\.php?action=register&event=$1&name=$2 [L]
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
i want to change urls of my website, but there many pages, so i cant change them manually.
so i need to change it from htaccess file.
i want to change the below url
http://demos.beusoft.com/ccjk/resource/arabic-translation-services/
with the
http://demos.beusoft.com/ccjk/arabic-translation-services/
i am using wordpress.
this is whole code ....
# BEGIN WordPress
RewriteEngine On
RewriteRule ^ccjk/resource/([^/]+)/$ demos.beusoft.com/ccjk/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ccjk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ccjk/index.php [L]
</IfModule>
# END WordPress
please help, how to rewrite the url from the htaccess file.
Try this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ccjk/
RewriteRule ^resource/([^/]+)/$ http://demos.beusoft.com/ccjk/$1/ [L,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ccjk/index.php [L]
</IfModule>
# END WordPress
I am using wordpress and need to redirect wp-login?action=register to /registration/ page,
first i did
Redirect /wp-login.php http://www.class-world.com/register/
but then it also keeps redirecting logout wp-login.php?action=logout so cant logout at all.
My question is how to only redirect action=register, instead of whole wp-login.php
I tried with following:
RewriteRule ^/wp-login.php\?action=register$ /register/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^/wp-login.php\?action=register$ /register/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
but no luck
Try this code :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^action=register
RewriteRule ^wp-login\.php$ /register/ [R=301]
I am using WordPress's permalink structure %category%/%postname%/ with the following htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The url's take the form http://www.example.com/category/postname/. I have a plugin where if you append ?m=gallery to the URL it will bring you to the posts' gallery. So http://www.example.com/category/postname/?m=gallery brings you to the gallery. I would like to be able to use http://www.example.com/category/postname/gallery/ instead. What do I need to modify in my htaccss to achieve my desired results? I would imagine it would be something like this RewriteRule ^(.+)/gallery$ $1?m=gallery
Edit - Current htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.+)/gallery/$ $1/?m=gallery [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Considering URL example you have provided (http://www.example.com/category/postname/gallery/ => http://www.example.com/category/postname/?m=gallery) you will need this sort of line:
RewriteRule ^(.+)/gallery/$ $1/?m=gallery [QSA]
Added missing slashes /
Added [QSA] flag (may not be really necessary actually).
You would need to put this rule somewhere on the top: after this line, for example: RewriteRule ^index\.php$ - [L]
Obviously, you ensure that WordPress will generate this kind of URLs: http://www.example.com/category/postname/gallery/
I have a Wordpress installation that works and a 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
Outside Wordpress I have created links like this:
http://www.test.com/butik/?my-url
I think it looks nice except for the "?". Is it simple to add something to my htaccess-file to remove it?
http://www.test.com/butik/my-url/ would be perfect. Does it matter if I run a file at the path http://www.test.com/butik/index.php? Would it collide?
If I'm understanding correctly, you can try the following:
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule (.*) $1%1? [L]
So, given your example, $1 would be /butik/ and %1 would be my-url (captured from the RewriteCond) Also, the first RewriteCond should prevent any conflicts with index.php requests.
Hope this helps.