开发者

is if else conditions available on htaccess?

开发者 https://www.devze.com 2022-12-20 02:09 出处:网络
I have a .htaccess file in the folder \"services\" in my website and have to give two urls following content of htaccess

I have a .htaccess file in the folder "services" in my website and have to give two urls following

content of htaccess

#------------------------
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^(.*)$ index.php?n=$1 [L,QSA] 
</IfModule>
$-------------------------

1. http://www.mysite.com/services/seo-work
2. http://www.mysite.com/services/online-editor

The 1st URL rewritten using htaccess like http://www.mys开发者_JAVA百科ite.com/services/index.php?s=seo-work This is working correct. but when i am uploading other file online-editor.php on the same folder "services", it is not working

so how the first url should show the page using index.php?s=seo-work if the page "online-editor.php" is not found in directory otherwise online-editor.php shoud show. I am programatically representing my problem below

if(IsFoundPageInDirectory(online-editor.php))
{
   GoToUrl(http://www.mysite.com/services/online-editor.php)
}
else
{
   GoToUrl(http://www.mysite.com/services/index.php?s=seo-work)
}

Please help me to get out of this problem Advance thanks for your reply


There is not really if/else conditions with ifModule in Apache configuration, but you can use the test in 2 cases : !module & module, like this:

<IfModule !module>
  # default directives
</IfModule>

<IfModule module>
  # decorator directives
</IfModule>


Check default wordpress .htaccess file. I think you're missing checks for existing files and directories. Something like

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php [L]
</IfModule>


Last I found answer.. thanks for the fist reply to lead me to get answer

<IfModule mod_rewrite.c>
  RewriteEngine on  
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^([^/]+)/$ $1.php 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?n=$1 [L,QSA]
</IfModule>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号