Pergunta

I have an htacess file in root directory as follows.

# 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

But now I have a sub domain called fun.example.com. I want to rewrite files inside that sub directory. Like fun/test.php?id=1 to fun/test/1. I am using get method. How to do that? Please note that, I do not have a htaccess inside sub domain folder. I read some tutorials. But couldn't find required answer

Foi útil?

Solução

Add a new htaccess file in your /fun/ directory (which I assume is the document root of the fun.example.com subdomain) with these rules:

Options -Multiviews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^fun\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} \ /+([^/]+)\.php\?id=([^&\ ]+)
RewriteRule ^ /%1/%2? [L,R]

RewriteCond %{HTTP_HOST} ^fun\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^/]+)/(.*)$ /$1.php?id=$2 [L]

Outras dicas

Place this code in /fun/.htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+test\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /test/%1? [R=302,L]

RewriteRule ^test/([0-9]+)/?$ /test.php?id=$1 [L,QSA,NC]

Insert this rule in your root .htaccess after RewriteBase / line:

RewriteCond %{HTTP_HOST} ^fun\. [NC]
RewriteRule ^ - [L]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top