.htaccess URL rewrites to the wrong file - .htaccess

Im trying to change my urls from mywebsite.co/keyword to mywebsite.co/web/keyword i found a few ways to do this but it always causes problems with my other rewrites here is what i have so far only problem with it is it wont redirect mywebsite.co/keyword to mywebsite.co/web/keyword
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^screenshot/ - [L]
# If requested resource exists as a file or directory, skip next two rules
RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule (.*) - [S=2]
# when there is no space make an external redirection
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^info/([0-9a-zA-Z]+) /search/info/info.php?keyword=$1 [QSA,L]
RewriteRule ^web/([0-9a-zA-Z]+) /search/web/index.php?search=$1 [QSA,L]
RewriteRule ^videos/([0-9a-zA-Z]+) /search/video/video.php?keyword=$1 [QSA,L]
RewriteRule ^images/([0-9a-zA-Z]+) /search/images/image.php?keyword=$1 [QSA,L]
RewriteRule ^news/([0-9a-zA-Z]+) /search/news/news.php?keyword=$1 [QSA,L]
RewriteRule ^products/([0-9a-zA-Z]+) /search/products/product.php?keyword=$1 [QSA,L]
RewriteRule ^maps/([0-9a-zA-Z]+) /search/maps/maps.php?keyword=$1 [QSA,L]
RewriteRule ^space/([0-9a-zA-Z]+) /search/space/space.php?keyword=$1 [QSA,L]
RewriteRule ^web/ /search/web/index.php [QSA,L]
RewriteRule ^info/ /search/info/info.php [QSA,L]
RewriteRule ^videos/ /search/video/video.php [QSA,L]
RewriteRule ^images/ /search/images/image.php [QSA,L]
RewriteRule ^news/ /search/news/news.php [QSA,L]
RewriteRule ^products/ /search/products/product.php [QSA,L]
RewriteRule ^maps/ /search/maps/maps.php [QSA,L]
RewriteRule ^space/ /search/space/space.php [QSA,L]

Have it this way:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^screenshot/ - [L]
# If requested resource exists as a file or directory, skip next two rules
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^info/([0-9a-zA-Z]+)/?$ /search/info/info.php?keyword=$1 [QSA,L]
RewriteRule ^web/([0-9a-zA-Z]+)/?$ /search/web/index.php?search=$1 [QSA,L]
RewriteRule ^videos/([0-9a-zA-Z]+)/?$ /search/video/video.php?keyword=$1 [QSA,L]
RewriteRule ^images/([0-9a-zA-Z]+)/?$ /search/images/image.php?keyword=$1 [QSA,L]
RewriteRule ^news/([0-9a-zA-Z]+)/?$ /search/news/news.php?keyword=$1 [QSA,L]
RewriteRule ^products/([0-9a-zA-Z]+)/?$ /search/products/product.php?keyword=$1 [QSA,L]
RewriteRule ^maps/([0-9a-zA-Z]+)/?$ /search/maps/maps.php?keyword=$1 [QSA,L]
RewriteRule ^space/([0-9a-zA-Z]+) /search/space/space.php?keyword=$1 [QSA,L]
RewriteRule ^web/?$ /search/web/index.php [QSA,L]
RewriteRule ^info/?$ /search/info/info.php [QSA,L]
RewriteRule ^videos/?$ /search/video/video.php [QSA,L]
RewriteRule ^images/?$ /search/images/image.php [QSA,L]
RewriteRule ^news/?$ /search/news/news.php [QSA,L]
RewriteRule ^products/?$ /search/products/product.php [QSA,L]
RewriteRule ^maps/?$ /search/maps/maps.php [QSA,L]
RewriteRule ^space/?$ /search/space/space.php [QSA,L]

Related

my hosting error 500 if use .htaccess

my hosting error 500 if use .htaccess
this my .htaccess file
RewriteEngine On
AllowOverride All
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteRule ^developer.html$ developer.php [QSA,L]
RewriteRule ^multishrink.html$ multishrink.php [QSA,L]
RewriteRule ^stats.html$ public-stats.php [QSA,L]
RewriteRule ^feed.rss feed.php [QSA,L]
RewriteRule ^([^/]+)\.qrcode$ qrcode.php?id=$1 [QSA,L]
RewriteRule ^api.php$ API/simple.php [QSA,L]
RewriteRule ^API/write/(get|post)$ API/write.php?method=$1 [QSA,L]
RewriteRule ^API/read/(get|post)$ API/read.php?method=$1 [QSA,L]
RewriteRule ^([^/]+)/stats$ stats.php?id=$1 [QSA,L]
RewriteRule ^([^/]+)/unlock$ unlock.php?id=$1 [QSA,L]
RewriteRule ^privacy.html$ privacy.php [QSA,L]
RewriteRule ^disclaimer.html$ disclaimer.php [QSA,L]
RewriteRule ^contact.html$ contact.php [QSA,L]
# If path is not a directory or file then apply RewriteRule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([0-9a-zA-Z-]{1,60})$ go.php?id=$1 [QSA,L]Options -Indexes
how to fix this

Activecollab htaccess convert to Caddyfile

please help with converting the htaccess file into caddyfile. We tried it with self-help but unsuccessfully. Can you look at it and help? Thank you
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^assets/(.*)$ public/assets/$1 [L]
RewriteRule ^wallpapers/(.*)$ public/wallpapers/$1 [L]
RewriteRule ^verify-existence$ public/verify.php [QSA,L]
RewriteRule ^proxy.php$ public/proxy.php [QSA,L]
RewriteRule ^api/v([0-9]*)/(.*)/?$ public/api.php?path_info=$2&api_version=$1 [QSA,L]
RewriteRule ^$ public/router.php [QSA,L]
RewriteRule ^(.*) public/router.php?path_info=$1 [QSA,L]
</IfModule>

htaccess issue when i try to access a directory

So here's my code:
RewriteEngine On
RewriteRule ^contact$ contact.php [QSA,L]
RewriteRule ^error$ error.php [QSA,L]
RewriteRule ^([^/.]+)/?$ product.php?weblink=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /error [L,R=301]
It's simple so when I try to access host/product-name it works but when I try to access for example a directory /blog or /blog/ redirect pe to error page specified by last rule. What's the problem?
You can do it this way
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^contact$ contact.php [QSA,L]
RewriteRule ^error$ error.php [QSA,L]
RewriteRule ^([^/.]+)/?$ product.php?weblink=$1 [L,QSA]
RewriteRule . /error [L,R=301]

htaccess rewrite error

What is wrong with this line
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?query=$1 [L]
I'm try rewrite links from
http://mysite.com/index.php?query=2012
to
http://mysite.com/2012
But i have 500 Internal Server Error
Also here is the content from my htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^software$ index.php?type=app
RewriteRule ^movies$ index.php?type=movie
RewriteRule ^games$ index.php?type=game
RewriteRule ^music$ index.php?type=music
RewriteRule ^other$ index.php?type=other
RewriteRule ^tv$ index.php?type=tv-show
RewriteRule ^ebooks$ index.php?type=ebooks
RewriteRule ^(.*)-(\d+)\.html$ download.php?id=$2 [L,NC]
RewriteRule ^site/([^/]*)$ /index.php?site=$1 [L]
RewriteRule ^([^/]*)$ /index.php?query=$1 [L]
Replace this rule:
RewriteRule ^([^/]*)$ /index.php?query=$1 [L]
with this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*)/?$ index.php?query=$1 [L,QSA]

Where to add www redirect code in a existing bbpress htaccess file?

I recently installed bbpress on a domain of mine. and it came with a .htaccess file which looks like this ->
# BEGIN bbPress
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page/([0-9]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^forum/([^/]+)/page/([0-9]+)/?$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^forum/([^/]+)/?$ /forum.php?id=$1 [L,QSA]
RewriteRule ^forum/?$ / [R=302,L,QSA]
RewriteRule ^topic/([^/]+)/page/([0-9]+)/?$ /topic.php?id=$1&page=$2 [L,QSA]
RewriteRule ^topic/([^/]+)/?$ /topic.php?id=$1 [L,QSA]
RewriteRule ^topic/?$ / [R=302,L,QSA]
RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ /tags.php?tag=$1&page=$2 [L,QSA]
RewriteRule ^tags/([^/]+)/?$ /tags.php?tag=$1 [L,QSA]
RewriteRule ^tags/?$ /tags.php [L,QSA]
RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&page=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ /profile.php?id=$1&tab=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&tab=$2&page=$3 [L,QSA]
RewriteRule ^profile/([^/]+)/?$ /profile.php?id=$1 [L,QSA]
RewriteRule ^profile/?$ /profile.php [L,QSA]
RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ /view.php?view=$1&page=$2 [L,QSA]
RewriteRule ^view/([^/]+)/?$ /view.php?view=$1 [L,QSA]
RewriteRule ^rss/?$ /rss.php [L,QSA]
RewriteRule ^rss/topics/?$ /rss.php?topics=1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/?$ /rss.php?forum=$1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/topics/?$ /rss.php?forum=$1&topics=1 [L,QSA]
RewriteRule ^rss/topic/([^/]+)/?$ /rss.php?topic=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/?$ /rss.php?tag=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/topics/?$ /rss.php?tag=$1&topics=1 [L,QSA]
RewriteRule ^rss/profile/([^/]+)/?$ /rss.php?profile=$1 [L,QSA]
RewriteRule ^rss/view/([^/]+)/?$ /rss.php?view=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>
# END bbPress
Now I want to add a non-www to www redirect code in it, which is ->
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
Where should I put it? I found here that I should put it right after RewriteEngine On but doing so makes the UI break. CSS file locations break.
So where should I put it?
Here is the final .htaccess file that's working -
# BEGIN bbPress
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [L,QSA]
RewriteRule ^page/([0-9]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^forum/([^/]+)/page/([0-9]+)/?$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^forum/([^/]+)/?$ /forum.php?id=$1 [L,QSA]
RewriteRule ^forum/?$ / [R=302,L,QSA]
RewriteRule ^topic/([^/]+)/page/([0-9]+)/?$ /topic.php?id=$1&page=$2 [L,QSA]
RewriteRule ^topic/([^/]+)/?$ /topic.php?id=$1 [L,QSA]
RewriteRule ^topic/?$ / [R=302,L,QSA]
RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ /tags.php?tag=$1&page=$2 [L,QSA]
RewriteRule ^tags/([^/]+)/?$ /tags.php?tag=$1 [L,QSA]
RewriteRule ^tags/?$ /tags.php [L,QSA]
RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&page=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ /profile.php?id=$1&tab=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&tab=$2&page=$3 [L,QSA]
RewriteRule ^profile/([^/]+)/?$ /profile.php?id=$1 [L,QSA]
RewriteRule ^profile/?$ /profile.php [L,QSA]
RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ /view.php?view=$1&page=$2 [L,QSA]
RewriteRule ^view/([^/]+)/?$ /view.php?view=$1 [L,QSA]
RewriteRule ^rss/?$ /rss.php [L,QSA]
RewriteRule ^rss/topics/?$ /rss.php?topics=1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/?$ /rss.php?forum=$1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/topics/?$ /rss.php?forum=$1&topics=1 [L,QSA]
RewriteRule ^rss/topic/([^/]+)/?$ /rss.php?topic=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/?$ /rss.php?tag=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/topics/?$ /rss.php?tag=$1&topics=1 [L,QSA]
RewriteRule ^rss/profile/([^/]+)/?$ /rss.php?profile=$1 [L,QSA]
RewriteRule ^rss/view/([^/]+)/?$ /rss.php?view=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>
# END bbPress
Changing the [R=301] part to [L,QSA] solved the 301 error part..

Resources