配置php .htaccess文件

发布于 2025-02-09 11:56:50 字数 639 浏览 3 评论 0原文

我对HTACCESS配置的工作方式不太了解,我正在努力编写一个配置,该配置负责以下两个方案: -

  1. 无需.php扩展名的服务器php页面请求,
  2. 而无需重定向,例如重新写入URL https://example.com/success/24

​为了适应第二种情况,我要使用第一个配置。我在.htaccess文件中使用的代码如下: -

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)$ /index.php?q=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?q=$1

请有人协助我应该如何容纳两种情况。

I don't know much on how htaccess configuration works and I'm struggling to write a configuration that takes care of two scenarios below:-

  1. server php pages request without .php extension
  2. rewrite the url without redirecting, for instance, rewrite
    https://example.com/success/24 to https://example.com?response=success&id=24

-Taking care of the first scenario is straight forward but on trying to accommodate the second scenario I'm messing with the first configuration. The code i'm using in the .htaccess file is as follows:-

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)$ /index.php?q=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?q=$1

Please someone assist on how I should accommodate the two use scenarios.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦情居士 2025-02-16 11:56:50

对于第一种情况,

这是.htacess的代码

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://www.example1.com%{REQUEST_URI} [L,NE,P]

For the first scenario

this is code for .htacess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://www.example1.com%{REQUEST_URI} [L,NE,P]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文