Two-language site and showing variables by .htaccess - php

i have such files:
index.php
<?php
echo $_REQUEST['cat_id'];
echo "***";
echo $_REQUEST['page'];
?>
and .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^ru/ index.php
RewriteRule ^ua/ index_ua.php
RewriteRule ^ru/(.*)/ index.php?cat_id=$1
RewriteRule ^ua/(.*)/ index_ua.php?cat_id=$1
RewriteRule ^ru/(.*)/([0-9]+)/ index.php?cat_id=$1&page=$2
RewriteRule ^ua/(.*)/([0-9]+)/ index_ua.php?cat_id=$1&page=$2
RewriteRule ^(.*)/ index.php?cat_id=$1
RewriteRule ^(.+)/([0-9]+)/ index.php?cat_id=$1&page=$2
</IfModule>
http://site2.com/ru/stranica/2/
shows:
index.php/stranica***2
http://site2.com/ru/stranica/
shows:
index.php/stranica***
http://site2.com/ru/
shows:
index.php***
Why $_REQUEST['cat_id'] show index.php, instead stranica ? Thanks!

It is because your regex is using greedy .* pattern and not using anchors where it is needed.
You can use these rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ru/?$ index.php [L,QSA]
RewriteRule ^ua/?$ index_ua.php [L,QSA]
RewriteRule ^ru/([^/]+)/?$ index.php?cat_id=$1 [L,QSA]
RewriteRule ^ua/([^/]+)/?$ index_ua.php?cat_id=$1 [L,QSA]
RewriteRule ^ru/([^/]+)/([0-9]+)/?$ index.php?cat_id=$1&page=$2 [L,QSA]
RewriteRule ^ua/([^/]+)/([0-9]+)/?$ index_ua.php?cat_id=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?cat_id=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?cat_id=$1 [L,QSA]
</IfModule>

Related

RewriteRule for subfolder htaccess

My url blog is here http://localhost/tibiaservers_11.10.19/blog
And my posts should be working like the following. after blog/
http://localhost/tibiaservers_11.10.19/blog/marketing-tools
http://localhost/tibiaservers_11.10.19/blog/the-cyber-house-rules
why isn't it working?
here is htaccess
Options +FollowSymLinks
RewriteEngine On
# FOR LOCALHOST RewriteBase /tibiaservers_11.10.19/
# FOR PRODUCTION RewriteBase /
RewriteBase /tibiaservers_11.10.19/
DirectoryIndex index.php
# przekierowanie na bez www
#RewriteCond %{HTTP_HOST} ^www\.tibiaservers\.net$
#RewriteRule ^/?$ "http\:\/\/tibiaservers\.net\/" [R=301,L]
<IfModule mod_rewrite.c>
# For Blog
RewriteRule ^blog/t-(.*)$ tagpost.php?id=$1 [L]
RewriteRule ^blog/c-(.*)$ catpost.php?id=$1 [L]
RewriteRule ^blog/a-(.*)-(.*)$ archives.php?month=$1&year=$2 [L]
# RewriteCond %{REQUEST_FILENAME} !-d [NC]
# RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^blog/(.*)$ viewpost.php?id=$1 [QSA,L]
##### - blog end
I think your RewriteRule should start with: ^tibiaservers_11.10.19/
This:
RewriteRule ^tibiaservers_11.10.19/blog/t\-(.*)$ tagpost.php?id=$1 [L]
Would match this url:
http://localhost/tibiaservers_11.10.19/blog/t-asdf
I use this tool for testing my .htaccess rules: htaccess.madewithlove.be

http access for only 1 domain name

so i have loads of domain names on 1 hosting plan but have a main one in my root i am using http acess
options -multiviews
options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^home$ index.php
RewriteRule ^dashboard$ dashboard.php
RewriteRule ^advertiser$ advertiser.php
RewriteRule ^add_campaign$ add_campaign.php
RewriteRule ^edit_campaign$ edit_campaign.php
RewriteRule ^stats$ view_statistics.php
RewriteRule ^login$ login.php
RewriteRule ^logout$ logout.php
RewriteRule ^withdrawals$ withdrawals.php
RewriteRule ^register$ register.php
RewriteRule ^report$ report.php
RewriteRule ^referrals$ referrals.php
RewriteRule ^contact$ contact.php
RewriteRule ^add_wallet$ add_wallet.php
RewriteRule ^payment_page$ payment_page.php
RewriteRule ^forgot_password$ forgot_password.php
RewriteRule ^my_account$ my_account.php
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ view_link.php?s=$1 [L]
RewriteRule ^page_([^/]+)/?$ pages.php?slug=$1 [L]
</IfModule>
The rest of my domain names will now not work because it will not let me access any of the files by doing domainname.com/folder is there any way to set these rules just for the main domain name??
Try to add RewriteCode that matches the main domain name. Like this
options -multiviews
options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourmaindomain.com$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^home$ index.php
RewriteRule ^dashboard$ dashboard.php
RewriteRule ^advertiser$ advertiser.php
RewriteRule ^add_campaign$ add_campaign.php
RewriteRule ^edit_campaign$ edit_campaign.php
RewriteRule ^stats$ view_statistics.php
RewriteRule ^login$ login.php
RewriteRule ^logout$ logout.php
RewriteRule ^withdrawals$ withdrawals.php
RewriteRule ^register$ register.php
RewriteRule ^report$ report.php
RewriteRule ^referrals$ referrals.php
RewriteRule ^contact$ contact.php
RewriteRule ^add_wallet$ add_wallet.php
RewriteRule ^payment_page$ payment_page.php
RewriteRule ^forgot_password$ forgot_password.php
RewriteRule ^my_account$ my_account.php
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ view_link.php?s=$1 [L]
RewriteRule ^page_([^/]+)/?$ pages.php?slug=$1 [L]
</IfModule>
Then the rewrite rules should only run if the domain matches.

htaccess rewrite rule stops at first occurrence

I have a htaccess file to match all of the occurrences. but it stops at second one. when i load /galeri/kategori/galeri-kategory-albumname/ it loads sayfa.php which has no relation with gallery page itself. It works fine on my localhost but trying to figure out why its not working in server.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)$ index.php?p=$1 [L]
RewriteRule ^(.*?)\/sayfa(.*?)$ index.php?p=$1&sayfa=$2 [L]
RewriteRule ^(.*?)\/kategori\/(.*?)\/$ index.php?p=$1&kategori=$2 [L]
RewriteRule ^(.*?)\/kategori\/(.*?)\/(.*?)\/$ index.php?p=$1&kategori=$2&sayfa=$3 [L}
Have it this way:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(.*)/kategori/(.*)/(.*)/?$ index.php?p=$1&kategori=$2&sayfa=$3 [L,QSA]
RewriteRule ^(.*)/kategori/(.*?)/?$ index.php?p=$1&kategori=$2 [L,QSA]
RewriteRule ^(.*)/sayfa(.*?)/?$ index.php?p=$1&sayfa=$2 [L,QSA]
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]

htaccess resulting in 500 internal error

The below code results in 500 internal error
RewriteBase /www/
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$profile.php?u=$1
RewriteRule ^albums/([a-zA-Z0-9_-]+)$view_albums.php?u=$1
RewriteRule ^albums/view_photo/([a-zA-Z0-9_-]+)$view_photo.php?uid=$1
Try this code
<IfModule mod_rewrite.c>
RewriteBase /www/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1 [L]
RewriteRule ^albums/([a-zA-Z0-9_-]+)$ view_albums.php?u=$1 [L]
RewriteRule ^albums/view_photo/([a-zA-Z0-9_-]+)$ view_photo.php?uid=$1 [L]
</ifModule>

Hide directory name from URL by .htaccess

When user types:
www.domain.com/standard/Public/Modules/home.php or
www.domain.com/standard/Public/Modules/contacts.php
(or anything that follows the same pattern)
I want the URL to be displayed like this:
www.domain.com/home
www.domain.com/contacts
...
My current .htaccess:
RewriteEngine on
RewriteRule ^home.php/?$ standard/Public/Modules/home.php [NC,L]
RewriteRule ^contacts.php/?$ standard/Public/Modules/contacts.php [NC,L]
You need to have this in your root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /standard/Public/Modules/login\.php [NC]
RewriteRule ^standard/Public/Modules/login\.php$ /home [L,NC,R=301]
RewriteCond %{THE_REQUEST} /standard/Public/Modules/logout\.php [NC]
RewriteRule ^standard/Public/Modules/logout\.php$ /contacts [L,NC,R=301]
RewriteRule ^home/?$ /standard/Public/Modules/login.php [NC,L]
RewriteRule ^contacts/?$ /standard/Public/Modules/logout.php [NC,L]
I use this, no need to individually set rewrites for pages
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
For example
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)-product(.*).html$ /products/view/$2 [L]
RewriteRule ^(.*)-cat(.*).html$ /products/listing/$2 [L]
RewriteRule ^products.html$ /products/listing/ [L]
RewriteRule ^bioproducts.html$ /products/bio_listing/ [L]
RewriteRule ^aboutus.html$ /static/index/15 [L]
RewriteRule ^contacts.html$ /static/contacts [L]
RewriteRule ^(.*)-partners(.*).html /partners/index/$2 [L]
</IfModule>

Categories