Apache:重写URL;从URL中删除文件名和文件扩展名

时间:2017-08-12 20:10:19

标签: .htaccess mod-rewrite url-rewriting httpd.conf

我知道这个问题经常在这里被问到。但是,当我尝试使用我发现的任何解决方案时,我得到的错误是找不到URL或者根本没有更改URL。

Linux版本:Red Hat 4.8.5-4

Apache版本:2.4.6(CentOS)

Python版本:3.5.2

我的httpd.conf:

ServerRoot "/home/deev/webapps/workload/apache2"

LoadModule authz_core_module modules/mod_authz_core.so
LoadModule dir_module        modules/mod_dir.so
LoadModule env_module        modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module       modules/mod_mime.so
LoadModule rewrite_module    modules/mod_rewrite.so
LoadModule setenvif_module   modules/mod_setenvif.so
LoadModule wsgi_module       modules/mod_wsgi.so
LoadModule unixd_module      modules/mod_unixd.so

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/deev/logs/user/access_workload.log combined
ErrorLog /home/deev/logs/user/error_workload.log

DirectoryIndex index.py
DocumentRoot /home/deev/webapps/workload/htdocs

Listen 23805
KeepAlive Off
SetEnvIf X-Forwarded-SSL on HTTPS=1
ServerLimit 1
StartServers 1
MaxRequestWorkers 5
MinSpareThreads 1
MaxSpareThreads 3
ThreadsPerChild 5

WSGIDaemonProcess workload processes=2 threads=12 python-path=/home/deev/webapps/workload/lib/python3.5
WSGIProcessGroup workload
WSGIRestrictEmbedded On
WSGILazyInitialization On

WSGIPythonPath /home/deev/webapps/workload/htdocs/
WSGIScriptAlias /index /home/deev/webapps/workload/htdocs/index.py
#WSGIScriptAlias / /index

<Directory /home/deev/webapps/workload/htdocs>
    # enabeling .htaccess file
    AllowOverride All
    # activating mod_rewrite for this dir
    RewriteEngine on 
    # setting the base URL for rewrites to / or the root dir for the website (home/deev/webapps/workload/htdocs/ == /)
    RewriteBase /
</Directory>

我的.htaccess(在我网站的根目录中):

RewriteEngine On
RewriteBase /

# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.py [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.py/*(.*) /$1$2 [R=301,NE,L]

# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.py/$1 [L]

我对这种语言没有任何经验,并希望快速解决这个问题,以便我可以继续使用python,但对我来说似乎相当困难。另外,如果在httpd.conf文件中我将WSGIScriptAlias从“/ index”更改为“/”,我会收到Errorpage:

未找到

在服务器上找不到请求的URL。如果您手动输入了URL,请检查拼写,然后重试。

0 个答案:

没有答案